Changeset afefe75
- Timestamp:
- 02/04/21 21:46:29 (4 years ago)
- Branches:
- master
- Children:
- ac51326
- Parents:
- de9d697
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
Farmatiko/Controllers/FarmatikoController.cs
rde9d697 rafefe75 1 1 using System.Collections.Generic; 2 2 using System.Threading.Tasks; 3 using FarmatikoData.DTOs; 3 4 using FarmatikoData.Models; 4 5 using FarmatikoServices.FarmatikoServiceInterfaces; … … 77 78 [HttpGet] 78 79 [Route("api/medicines")] 79 public async Task<IEnumerable<Medicine >> GetMedicines()80 public async Task<IEnumerable<MedicineDTO>> GetMedicines() 80 81 { 81 82 return await _service.GetMedicines(); … … 104 105 [HttpGet] 105 106 [Route("api/pharmacy")] 106 public async Task<IEnumerable<Pharmacy >> GetPharmacies()107 public async Task<IEnumerable<PharmacyDTO>> GetPharmacies() 107 108 { 108 109 return await _service.GetPharmacies(); -
Farmatiko/Controllers/PharmacyHeadController.cs
rde9d697 rafefe75 30 30 //POST 31 31 32 [HttpP ut]32 [HttpPost] 33 33 [Route("api/pharmacyhead/update")] 34 34 public async Task<IActionResult> UpdatePharmacyHead([FromBody] PharmacyHeadDto pharmacyHead) -
Farmatiko/Startup.cs
rde9d697 rafefe75 18 18 using FarmatikoServices.Infrastructure; 19 19 using System; 20 using Newtonsoft.Json.Serialization;21 20 namespace Farmatiko 22 21 { -
FarmatikoData/FarmatikoRepo/Repository.cs
rde9d697 rafefe75 63 63 return Pandemic; 64 64 } 65 66 public async Task<IEnumerable<Pharmacy>> GetPharmacies() 67 { 68 var Pharmacies = await _context.Pharmacies.Take(5).ToListAsync(); 65 public async Task<List<Pharmacy>> GetPharmacies() 66 { 67 var Pharmacies = await _context.Pharmacies.Select(x => new Pharmacy 68 { 69 Name = x.Name, 70 Location = x.Location, 71 Address = x.Address, 72 WorkAllTime = x.WorkAllTime, 73 PheadId = x.PheadId 74 }).Take(5).ToListAsync(); 69 75 return Pharmacies; 70 76 } … … 85 91 { 86 92 var SearchQuery = await _context.HealthFacilities 87 .Where(x => x.Name. Contains(query))93 .Where(x => x.Name.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0) 88 94 .OrderBy(x => x.Name).ToListAsync(); 89 95 … … 94 100 { 95 101 var SearchQuery = await _context.Medicines 96 .Where(x => x.Name. Contains(query))102 .Where(x => x.Name.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0) 97 103 .OrderBy(x => x.Name).ToListAsync(); 98 104 … … 102 108 public async Task<IEnumerable<Pharmacy>> SearchPharmacies(string query) 103 109 { 104 var SearchQuery = await _context.Pharmacies .Take(5)105 .Where(x => x.Name. Contains(query))110 var SearchQuery = await _context.Pharmacies 111 .Where(x => x.Name.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0) 106 112 .OrderBy(x => x.Name).ToListAsync(); 107 113 … … 111 117 public async Task<IEnumerable<HealthcareWorker>> SearchWorkers(string query) 112 118 { 113 var SearchQuery = await _context.HealthcareWorkers .Take(5)114 .Where(x => x.Name. Contains(query))119 var SearchQuery = await _context.HealthcareWorkers 120 .Where(x => x.Name.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0) 115 121 .OrderBy(x => x.Name).ToListAsync(); 116 122 … … 291 297 } 292 298 } 299 300 public async Task<List<PharmacyHeadMedicine>> GetAllPHMedicines() 301 { 302 var list = await _context.PharmacyHeadMedicines.ToListAsync(); 303 return list; 304 } 293 305 } 294 306 } -
FarmatikoData/FarmatikoRepoInterfaces/IRepository.cs
rde9d697 rafefe75 18 18 ICollection<Medicine> GetMedicines(); 19 19 Task<Pandemic> GetPandemic(); 20 Task<IEnumerable<Pharmacy>> GetPharmacies(); 20 Task<List<PharmacyHeadMedicine>> GetAllPHMedicines(); 21 Task<List<Pharmacy>> GetPharmacies(); 21 22 Task<Pharmacy> GetPharmacy(int id); 22 23 Task<HealthcareWorker> GetWorker(int id); -
FarmatikoData/Migrations/20210124191844_InitialMigration.cs
rde9d697 rafefe75 172 172 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 173 173 DeletedOn = table.Column<DateTime>(nullable: true), 174 PheadId = table.Column<int>(nullable: false),174 PheadId = table.Column<int>(nullable: true), 175 175 HeadId = table.Column<int>(nullable: true), 176 MedicineId = table.Column<int>(nullable: false)176 MedicineId = table.Column<int>(nullable: true) 177 177 }, 178 178 constraints: table => -
FarmatikoServices/FarmatikoServiceInterfaces/IService.cs
rde9d697 rafefe75 1 using FarmatikoData.Models; 1 using FarmatikoData.DTOs; 2 using FarmatikoData.Models; 2 3 using System.Collections.Generic; 3 4 using System.Linq; … … 18 19 Task<Medicine> GetMedicine(int id); 19 20 Task<IEnumerable<Medicine>> SearchMedicines(string query); 20 Task< IEnumerable<Medicine>> GetMedicines();21 Task<List<MedicineDTO>> GetMedicines(); 21 22 Task<Pandemic> GetPandemic(); 22 Task< IEnumerable<Pharmacy>> GetPharmacies();23 Task<List<PharmacyDTO>> GetPharmacies(); 23 24 Task<IEnumerable<Pharmacy>> SearchPharmacies(string query); 24 25 Task<Pharmacy> GetPharmacy(int id); -
FarmatikoServices/Services/Service.cs
rde9d697 rafefe75 1 using FarmatikoData.FarmatikoRepoInterfaces; 1 using FarmatikoData.DTOs; 2 using FarmatikoData.FarmatikoRepoInterfaces; 2 3 using FarmatikoData.Models; 3 4 using FarmatikoServices.FarmatikoServiceInterfaces; … … 42 43 } 43 44 44 public async Task< IEnumerable<Medicine>> GetMedicines()45 public async Task<List<MedicineDTO>> GetMedicines() 45 46 { 46 47 var Medicines = await _repository.GetMedicinesAsync(); 47 return Medicines; 48 List<MedicineDTO> list = new List<MedicineDTO>(); 49 var listPHMedicines = await _repository.GetAllPHMedicines(); 50 foreach(var med in Medicines) 51 { 52 var heads = listPHMedicines.Where(x => x.MedicineId == med.Id).Select(x => x.Head).ToList(); 53 List<string> headNames = new List<string>(); 54 headNames = heads.Select(x => x.Name).ToList(); 55 MedicineDTO medicine = new MedicineDTO() 56 { 57 Name = med.Name, 58 Manufacturer = med.Manufacturer, 59 Packaging = med.Packaging, 60 Form = med.Form, 61 Price = med.Price, 62 Strength = med.Strength, 63 WayOfIssuing = med.WayOfIssuing, 64 HeadNames = headNames 65 }; 66 67 list.Add(medicine); 68 } 69 70 return list; 48 71 } 49 72 … … 54 77 } 55 78 56 public async Task< IEnumerable<Pharmacy>> GetPharmacies()79 public async Task<List<PharmacyDTO>> GetPharmacies() 57 80 { 58 81 var Pharmacies = await _repository.GetPharmacies(); 59 return Pharmacies; 82 List<PharmacyDTO> pharmacies = new List<PharmacyDTO>(); 83 84 foreach(var pharm in Pharmacies) 85 { 86 PharmacyDTO pharmacyDTO = new PharmacyDTO() 87 { 88 Name = pharm.Name, 89 Location = pharm.Location, 90 Address = pharm.Address, 91 WorkAllTime = pharm.WorkAllTime, 92 HeadName = pharm.PharmacyHead.Name 93 }; 94 pharmacies.Add(pharmacyDTO); 95 } 96 return pharmacies; 60 97 } 61 98
Note:
See TracChangeset
for help on using the changeset viewer.