Changeset e0cdea2
- Timestamp:
- 02/08/21 16:39:25 (4 years ago)
- Branches:
- master
- Children:
- 8eb1e21, dae4cde
- Parents:
- 0a694bb
- Files:
-
- 1 added
- 23 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
Farmatiko/ClientApp/src/app/admin/admin.component.ts
r0a694bb re0cdea2 124 124 125 125 rejectRequest(req: IPharmacyHeadRequest) { 126 this.dataService.deleteClaimingRequest(req .id)126 this.dataService.deleteClaimingRequest(req) 127 127 .subscribe((status: boolean) => { 128 128 if(status) { … … 139 139 approveRequest(req: IPharmacyHeadRequest) { 140 140 if(req) { 141 if (req.PharmacyHead.Pharmacy == null){ 142 req.PharmacyHead.Pharmacy = []; 143 } 141 144 req.PharmacyHead.Pharmacy.push(req.Pharmacy); 142 145 this.dataService.updatePharmacyHead(req.PharmacyHead) -
Farmatiko/ClientApp/src/app/dashboard/dashboard.component.ts
r0a694bb re0cdea2 98 98 saveDeletedMedicines() { 99 99 this.dataService.updatePharmacyHead(this.head) 100 .subscribe((hd : IPharmacyHead) => {100 .subscribe((hd) => { 101 101 if(hd) { 102 102 this.openSnackBar("Success! Medicine deleted", "OK"); -
Farmatiko/ClientApp/src/app/shared/data.service.ts
r0a694bb re0cdea2 196 196 ); 197 197 } 198 deleteClaimingRequest( id: string) : Observable<boolean> {199 return this.http.post<boolean>(this.basePharmacyHead + '/requests/' + id, id)198 deleteClaimingRequest(req: IPharmacyHeadRequest) : Observable<boolean> { 199 return this.http.post<boolean>(this.basePharmacyHead + '/requests/' + req.id, req) 200 200 .pipe( 201 201 map((data) => { -
Farmatiko/Controllers/AdminController.cs
r0a694bb re0cdea2 61 61 [HttpPost] 62 62 [Route("api/pharmacyhead/requests/{Id}")] 63 public IActionResult RejectRequest([From Route] int Id)63 public IActionResult RejectRequest([FromBody] RequestPharmacyHead req) 64 64 { 65 bool Success = _adminService.RejectRequest( Id);65 bool Success = _adminService.RejectRequest(req); 66 66 return Ok(Success); 67 67 } -
Farmatiko/Controllers/FarmatikoController.cs
r0a694bb re0cdea2 84 84 [HttpGet] 85 85 [Route("api/medicines/search/{query}")] 86 public async Task<IEnumerable<Medicine >> SearchMedicines([FromRoute] string query)86 public async Task<IEnumerable<MedicineDTO>> SearchMedicines([FromRoute] string query) 87 87 { 88 88 return await _service.SearchMedicines(query); … … 97 97 [HttpGet] 98 98 [Route("api/pandemic")] 99 public async Task<Pandemic>GetPandemic()99 public Pandemic GetPandemic() 100 100 { 101 return await_service.GetPandemic();101 return _service.GetPandemic(); 102 102 } 103 103 //Pharmacy … … 111 111 [HttpGet] 112 112 [Route("api/pharmacy/search/{Query}")] 113 public async Task<IEnumerable<Pharmacy >> SearchPharmacies([FromRoute] string Query)113 public async Task<IEnumerable<PharmacyDTO>> SearchPharmacies([FromRoute] string Query) 114 114 { 115 115 return await _service.SearchPharmacies(Query); -
Farmatiko/Farmatiko.csproj
r0a694bb re0cdea2 52 52 </ItemGroup> 53 53 54 <ItemGroup> 55 <Folder Include="ExcellDocs\" /> 56 </ItemGroup> 57 54 58 <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') "> 55 59 <!-- Ensure Node.js is installed --> -
Farmatiko/Startup.cs
r0a694bb re0cdea2 54 54 55 55 services.AddScoped<IPHRepo, PHRepo>(); 56 services.Add Transient<IRepository, Repository>();57 services.Add Transient<IAdminRepo, AdminRepo>();56 services.AddScoped<IRepository, Repository>(); 57 services.AddScoped<IAdminRepo, AdminRepo>(); 58 58 59 services.Add Transient<IPHService, PHService>();59 services.AddScoped<IPHService, PHService>(); 60 60 services.AddTransient<IAdminService, AdminService>(); 61 61 services.AddTransient<IService, Service>(); -
FarmatikoData/FarmatikoDataContext.cs
r0a694bb re0cdea2 42 42 .ValueGeneratedOnAdd(); 43 43 44 /*modelBuilder.Entity<Medicine>() 45 .Property(x => x.Id) 46 .HasIdentityOptions(startValue: 1); 44 modelBuilder.Entity<PharmacyHeadMedicine>() 45 .Property(p => p.Id) 46 .ValueGeneratedOnAdd(); 47 48 modelBuilder.Entity<Medicine>() 49 .Property(p => p.Id) 50 .ValueGeneratedOnAdd(); 47 51 48 52 modelBuilder.Entity<Pharmacy>() 49 .Property( x => x.Id)50 . HasIdentityOptions(startValue: 1);53 .Property(p => p.Id) 54 .ValueGeneratedOnAdd(); 51 55 52 56 modelBuilder.Entity<PharmacyHead>() 53 .Property(x => x.Id) 54 .HasIdentityOptions(startValue: 1); 55 56 modelBuilder.Entity<PharmacyHeadMedicine>() 57 .Property(x => x.Id) 58 .HasIdentityOptions(startValue: 1); 59 60 modelBuilder.Entity<RequestPharmacyHead>() 61 .Property(x => x.Id) 62 .HasIdentityOptions(startValue: 1);*/ 63 64 /*modelBuilder.Entity<User>() 65 .Property(x => x.Id) 66 .HasIdentityOptions(startValue: 1); 67 68 modelBuilder.Entity<PharmacyHeadMedicine>() 69 .HasKey(phm => new { phm.PheadId, phm.MedicineId }); 70 71 modelBuilder.Entity<PharmacyHead>() 72 .HasMany<Pharmacy>(p => p.Pharmacy) 73 .WithOne(p => p.PharmacyHead) 74 .HasForeignKey(); 57 .HasMany<Pharmacy>(p => p.Pharmacies) 58 .WithOne(p => p.PharmacyHead); 75 59 76 60 modelBuilder.Entity<Pharmacy>() 77 61 .HasOne<PharmacyHead>(p => p.PharmacyHead) 78 .WithMany(p => p.Pharmacy); 79 */ 62 .WithMany(p => p.Pharmacies) 63 .HasForeignKey(x => x.PheadId); 64 65 modelBuilder.Entity<PharmacyHeadMedicine>() 66 .HasKey(bc => new { bc.PheadId, bc.MedicineId}); 67 68 modelBuilder.Entity<PharmacyHeadMedicine>() 69 .HasOne(bc => bc.Head) 70 .WithMany(b => b.Medicines) 71 .HasForeignKey(bc => bc.PheadId); 72 73 modelBuilder.Entity<PharmacyHeadMedicine>() 74 .HasOne(bc => bc.Medicine) 75 .WithMany(c => c.Medicines) 76 .HasForeignKey(bc => bc.MedicineId); 77 80 78 81 79 base.OnModelCreating(modelBuilder); -
FarmatikoData/FarmatikoRepo/AdminRepo.cs
r0a694bb re0cdea2 20 20 public async Task<IEnumerable<RequestPharmacyHead>> GetClaimingRequests() 21 21 { 22 var reqs = await _context.PHRequests.OrderBy(x => x.Head.Name).ToListAsync(); 22 var reqs = await _context.PHRequests.Select(x => new RequestPharmacyHead 23 { 24 Head = x.Head, 25 Pharmacy = x.Pharmacy 26 }).OrderBy(x => x.Head.Name).ToListAsync(); 23 27 return reqs; 24 28 } … … 35 39 } 36 40 //POST 37 public async void RemoveClaimRequest(int Id)41 public void RemoveClaimRequest(RequestPharmacyHead request) 38 42 { 39 var req = _context.PHRequests.Where(x => x.Id == Id).FirstOrDefault(); 43 var req = _context.PHRequests.Select(x => new RequestPharmacyHead { Head = x.Head, Pharmacy = x.Pharmacy, Id = x.Id}) 44 .Where(x => x.Head.Email.Equals(request.Head.Email)).FirstOrDefault(); 40 45 _context.PHRequests.Remove(req); 41 await _context.SaveChangesAsync();46 _context.SaveChanges(); 42 47 } 43 48 } -
FarmatikoData/FarmatikoRepo/PHRepo.cs
r0a694bb re0cdea2 41 41 public async Task UpdatePharmacyHead(PharmacyHead pharmacyHead) 42 42 { 43 var Phead = await _context.PharmacyHeads.Where(x => x.Email == pharmacyHead.Email).FirstOrDefaultAsync();44 var EditedPHead = await _context.PharmacyHeads. AsNoTracking<PharmacyHead>().Where(x => x.Email == pharmacyHead.Email).FirstOrDefaultAsync();43 var user = await _context.Users.Where(x => x.Email == pharmacyHead.Email).FirstOrDefaultAsync(); 44 var EditedPHead = await _context.PharmacyHeads.Where(x => x.Email.Equals(pharmacyHead.Email)).FirstOrDefaultAsync(); 45 45 46 if (!EditedPHead.Email.Equals(pharmacyHead.Email)) 46 /*if (!EditedPHead.Email.Equals(pharmacyHead.Email) && !user.Email.Equals(pharmacyHead.Email)) 47 { 47 48 EditedPHead.Email = pharmacyHead.Email; 49 user.Email = pharmacyHead.Email; 50 }*/ 48 51 49 if (!EditedPHead.Name.Equals(pharmacyHead.Name)) 52 if (!EditedPHead.Name.Equals(pharmacyHead.Name) || !user.Name.Equals(pharmacyHead.Name)) 53 { 50 54 EditedPHead.Name = pharmacyHead.Name; 55 user.Name = pharmacyHead.Name; 56 } 51 57 52 if (!EditedPHead.Password.Equals(pharmacyHead.Password)) 58 if (!EditedPHead.Password.Equals(pharmacyHead.Password) || !user.Password.Equals(pharmacyHead.Password)) 59 { 53 60 EditedPHead.Password = pharmacyHead.Password; 61 user.Password = pharmacyHead.Password; 62 } 63 /*if (EditedPHead.Pharmacies != null) 64 { 65 if (EditedPHead.Pharmacies.Count() > 0) 66 if (!EditedPHead.Pharmacies.Equals(pharmacyHead.Pharmacies)) 67 EditedPHead.Pharmacies = pharmacyHead.Pharmacies; 68 } 69 if (EditedPHead.Medicines != null) 70 { 71 if (EditedPHead.Medicines.Count() > 0) 72 { 73 if (!EditedPHead.Medicines.Equals(pharmacyHead.Medicines)) 74 EditedPHead.Medicines = pharmacyHead.Medicines; 75 76 } 77 78 }*/ 54 79 55 if (!EditedPHead.Pharmacies.Equals(pharmacyHead.Pharmacies)) 56 EditedPHead.Pharmacies = pharmacyHead.Pharmacies; 57 58 if (!EditedPHead.Medicines.Equals(pharmacyHead.Medicines)) 59 EditedPHead.Medicines = pharmacyHead.Medicines; 60 61 await _context.SaveChangesAsync(); 80 _context.SaveChanges(); 62 81 } 63 82 public async Task ClaimPharmacy(RequestPharmacyHead pharmacy) 64 83 { 84 var phead = _context.PharmacyHeads.Where(x => x.Email.Equals(pharmacy.Head.Email)).FirstOrDefault(); 85 pharmacy.Head = phead; 65 86 await _context.PHRequests.AddAsync(pharmacy); 66 87 await _context.SaveChangesAsync(); -
FarmatikoData/FarmatikoRepo/Repository.cs
r0a694bb re0cdea2 19 19 public async Task<IEnumerable<HealthcareWorker>> GetAllWorkers() 20 20 { 21 var Workers = await _context.HealthcareWorkers.Take(5).ToListAsync(); 21 var Workers = await _context.HealthcareWorkers.Select(x => new HealthcareWorker 22 { 23 Id = x.Id, 24 Name = x.Name, 25 Branch = x.Branch, 26 Facility = x.Facility, 27 Title = x.Title 28 }).Take(5).ToListAsync(); 22 29 return Workers; 23 30 } … … 54 61 Packaging = x.Packaging 55 62 56 }).Take( 3).ToListAsync();63 }).Take(5).ToListAsync(); 57 64 return Medicines; 58 65 } … … 92 99 { 93 100 var SearchQuery = await _context.HealthFacilities 94 .Where(x => x.Name.ToLowerInvariant().Contains(query.ToLowerInvariant())) 101 .Where(x => x.Name.ToLower().Contains(query.ToLower()) 102 || x.Municipality.ToLower().Contains(query.ToLower()) 103 || x.Type.ToLower().Contains(query.ToLower())).Take(5) 95 104 .OrderBy(x => x.Name).ToListAsync(); 96 105 … … 101 110 { 102 111 var SearchQuery = await _context.Medicines 103 .Where(x => x.Name.ToLowerInvariant().Contains(query.ToLowerInvariant())) 112 .Where(x => x.Name.ToLower().Contains(query.ToLower()) 113 || x.Form.ToLower().Contains(query.ToLower()) 114 || x.Strength.ToLower().Contains(query.ToLower()) 115 || x.Packaging.ToLower().Contains(query.ToLower())).Take(20) 104 116 .OrderBy(x => x.Name).ToListAsync(); 105 117 … … 110 122 { 111 123 var SearchQuery = await _context.Pharmacies 112 .Where(x => x.Name.ToLowerInvariant().Contains(query.ToLowerInvariant())) 124 .Where(x => x.Name.ToLower().Contains(query.ToLower()) 125 || x.PharmacyHead.Name.ToLower().Contains(query.ToLower())).Take(5) 113 126 .OrderBy(x => x.Name).ToListAsync(); 114 127 … … 118 131 public async Task<IEnumerable<HealthcareWorker>> SearchWorkers(string query) 119 132 { 120 var SearchQuery = await _context.HealthcareWorkers 121 .Where(x => x.Name.ToLowerInvariant().Contains(query.ToLowerInvariant())) 133 var SearchQuery = await _context.HealthcareWorkers.Include(x => x.Facility) 134 .Where(x => x.Name.ToLower().Contains(query.ToLower()) 135 || x.Facility.Name.ToLower().Contains(query.ToLower())).Take(20) 122 136 .OrderBy(x => x.Name).ToListAsync(); 123 137 … … 146 160 public async Task AddPharmacy(Pharmacy pharmacy) 147 161 { 148 await _context.Pharmacies.AddAsync(pharmacy); 149 _context.SaveChanges(); 162 pharmacy.Id = 0; 163 if (pharmacy.Id == 0) 164 { 165 var phars = _context.Pharmacies.Select(x => new Pharmacy 166 { 167 Name = x.Name, 168 Location = x.Location, 169 Address = x.Address 170 }).ToList(); 171 var pharms = phars.Where(x => x.Name.Equals(pharmacy.Name) && x.Location.Equals(pharmacy.Location) && x.Address.Equals(pharmacy.Address)).ToList(); 172 if (pharms is null || pharms.Count() == 0) 173 { 174 await _context.Pharmacies.AddAsync(pharmacy); 175 _context.SaveChanges(); 176 } 177 178 } 150 179 } 151 180 … … 242 271 { 243 272 var PHead = await _context.PharmacyHeads.Where(x => x.Id == Id).FirstOrDefaultAsync(); 244 PHead.DeletedOn = DateTime.UtcNow; 245 await _context.SaveChangesAsync(); 273 var user = await _context.Users.Where(x => x.Email.Equals(PHead.Email)).FirstOrDefaultAsync(); 274 _context.PharmacyHeads.Remove(PHead); 275 _context.Users.Remove(user); 276 _context.SaveChanges(); 246 277 } 247 278 … … 290 321 return phmeds; 291 322 } 292 293 public async Task<bool> AddUser(User user)323 324 /*public async Task<bool> AddUser(User user) 294 325 { 295 326 if (user.Id == 0) … … 303 334 }).ToListAsync(); 304 335 var usr = users.Where(x => x.Email.Equals(user.Email)).ToList(); 305 if (usr != null ||usr.Count() > 0)336 if (usr != null && usr.Count() > 0) 306 337 { 307 338 return true; … … 315 346 } 316 347 return false; 317 } 348 }*/ 318 349 319 350 public async Task<List<PharmacyHeadMedicine>> GetAllPHMedicines() … … 329 360 return list; 330 361 } 362 363 public ICollection<PharmacyHeadMedicine> GetPHMedicines() 364 { 365 var meds = _context.PharmacyHeadMedicines.Select(x => new PharmacyHeadMedicine 366 { 367 PheadId = x.PheadId, 368 Head = x.Head, 369 MedicineId = x.MedicineId, 370 Medicine = x.Medicine 371 }).ToList(); 372 return meds; 373 } 331 374 } 332 375 } -
FarmatikoData/FarmatikoRepoInterfaces/IAdminRepo.cs
r0a694bb re0cdea2 12 12 Task<IEnumerable<RequestPharmacyHead>> GetClaimingRequests(); 13 13 Task<IEnumerable<PharmacyHead>> GetPharmacyHeads(); 14 void RemoveClaimRequest( intId);14 void RemoveClaimRequest(RequestPharmacyHead Id); 15 15 } 16 16 } -
FarmatikoData/FarmatikoRepoInterfaces/IRepository.cs
r0a694bb re0cdea2 46 46 User GetRole(string userName); 47 47 ICollection<PharmacyHeadMedicine> GetPHMedicines(string email); 48 Task<bool> AddUser(User user); 48 ICollection<PharmacyHeadMedicine> GetPHMedicines(); 49 //Task<bool> AddUser(User user); 49 50 } 50 51 } -
FarmatikoData/Migrations/20210208041424_Initial-Create.Designer.cs
r0a694bb re0cdea2 11 11 { 12 12 [DbContext(typeof(FarmatikoDataContext))] 13 [Migration("2021020 5174704_Initial-Migration")]14 partial class Initial Migration13 [Migration("20210208041424_Initial-Create")] 14 partial class InitialCreate 15 15 { 16 16 protected override void BuildTargetModel(ModelBuilder modelBuilder) … … 207 207 .HasColumnType("text"); 208 208 209 b.Property<int?>("PharmacyHeadId") 210 .HasColumnType("integer"); 211 212 b.Property<int>("PheadId") 209 b.Property<int?>("PheadId") 213 210 .HasColumnType("integer"); 214 211 … … 218 215 b.HasKey("Id"); 219 216 220 b.HasIndex("Ph armacyHeadId");217 b.HasIndex("PheadId"); 221 218 222 219 b.ToTable("Pharmacies"); … … 302 299 .HasColumnType("timestamp without time zone"); 303 300 304 b.Property<int >("HeadId")305 .HasColumnType("integer"); 306 307 b.Property<int >("PharmacyId")301 b.Property<int?>("HeadId") 302 .HasColumnType("integer"); 303 304 b.Property<int?>("PharmacyId") 308 305 .HasColumnType("integer"); 309 306 … … 363 360 b.HasOne("FarmatikoData.Models.PharmacyHead", "PharmacyHead") 364 361 .WithMany("Pharmacies") 365 .HasForeignKey("Ph armacyHeadId");362 .HasForeignKey("PheadId"); 366 363 }); 367 364 … … 392 389 b.HasOne("FarmatikoData.Models.PharmacyHead", "Head") 393 390 .WithMany() 394 .HasForeignKey("HeadId") 395 .OnDelete(DeleteBehavior.Cascade) 396 .IsRequired(); 391 .HasForeignKey("HeadId"); 397 392 398 393 b.HasOne("FarmatikoData.Models.Pharmacy", "Pharmacy") 399 394 .WithMany() 400 .HasForeignKey("PharmacyId") 401 .OnDelete(DeleteBehavior.Cascade) 402 .IsRequired(); 395 .HasForeignKey("PharmacyId"); 403 396 }); 404 397 #pragma warning restore 612, 618 -
FarmatikoData/Migrations/20210208041424_Initial-Create.cs
r0a694bb re0cdea2 5 5 namespace FarmatikoData.Migrations 6 6 { 7 public partial class Initial Migration: Migration7 public partial class InitialCreate : Migration 8 8 { 9 9 protected override void Up(MigrationBuilder migrationBuilder) … … 150 150 Address = table.Column<string>(nullable: false), 151 151 WorkAllTime = table.Column<bool>(nullable: false), 152 PheadId = table.Column<int>(nullable: false), 153 PharmacyHeadId = table.Column<int>(nullable: true) 152 PheadId = table.Column<int>(nullable: true) 154 153 }, 155 154 constraints: table => … … 157 156 table.PrimaryKey("PK_Pharmacies", x => x.Id); 158 157 table.ForeignKey( 159 name: "FK_Pharmacies_PharmacyHeads_Ph armacyHeadId",160 column: x => x.Ph armacyHeadId,158 name: "FK_Pharmacies_PharmacyHeads_PheadId", 159 column: x => x.PheadId, 161 160 principalTable: "PharmacyHeads", 162 161 principalColumn: "Id", … … 201 200 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 202 201 DeletedOn = table.Column<DateTime>(nullable: true), 203 HeadId = table.Column<int>(nullable: false),204 PharmacyId = table.Column<int>(nullable: false)202 HeadId = table.Column<int>(nullable: true), 203 PharmacyId = table.Column<int>(nullable: true) 205 204 }, 206 205 constraints: table => … … 212 211 principalTable: "PharmacyHeads", 213 212 principalColumn: "Id", 214 onDelete: ReferentialAction. Cascade);213 onDelete: ReferentialAction.Restrict); 215 214 table.ForeignKey( 216 215 name: "FK_PHRequests_Pharmacies_PharmacyId", … … 218 217 principalTable: "Pharmacies", 219 218 principalColumn: "Id", 220 onDelete: ReferentialAction. Cascade);219 onDelete: ReferentialAction.Restrict); 221 220 }); 222 221 … … 227 226 228 227 migrationBuilder.CreateIndex( 229 name: "IX_Pharmacies_Ph armacyHeadId",228 name: "IX_Pharmacies_PheadId", 230 229 table: "Pharmacies", 231 column: "Ph armacyHeadId");230 column: "PheadId"); 232 231 233 232 migrationBuilder.CreateIndex( -
FarmatikoData/Migrations/FarmatikoDataContextModelSnapshot.cs
r0a694bb re0cdea2 205 205 .HasColumnType("text"); 206 206 207 b.Property<int?>("PharmacyHeadId") 208 .HasColumnType("integer"); 209 210 b.Property<int>("PheadId") 207 b.Property<int?>("PheadId") 211 208 .HasColumnType("integer"); 212 209 … … 216 213 b.HasKey("Id"); 217 214 218 b.HasIndex("Ph armacyHeadId");215 b.HasIndex("PheadId"); 219 216 220 217 b.ToTable("Pharmacies"); … … 300 297 .HasColumnType("timestamp without time zone"); 301 298 302 b.Property<int >("HeadId")303 .HasColumnType("integer"); 304 305 b.Property<int >("PharmacyId")299 b.Property<int?>("HeadId") 300 .HasColumnType("integer"); 301 302 b.Property<int?>("PharmacyId") 306 303 .HasColumnType("integer"); 307 304 … … 361 358 b.HasOne("FarmatikoData.Models.PharmacyHead", "PharmacyHead") 362 359 .WithMany("Pharmacies") 363 .HasForeignKey("Ph armacyHeadId");360 .HasForeignKey("PheadId"); 364 361 }); 365 362 … … 390 387 b.HasOne("FarmatikoData.Models.PharmacyHead", "Head") 391 388 .WithMany() 392 .HasForeignKey("HeadId") 393 .OnDelete(DeleteBehavior.Cascade) 394 .IsRequired(); 389 .HasForeignKey("HeadId"); 395 390 396 391 b.HasOne("FarmatikoData.Models.Pharmacy", "Pharmacy") 397 392 .WithMany() 398 .HasForeignKey("PharmacyId") 399 .OnDelete(DeleteBehavior.Cascade) 400 .IsRequired(); 393 .HasForeignKey("PharmacyId"); 401 394 }); 402 395 #pragma warning restore 612, 618 -
FarmatikoData/Models/Pharmacy.cs
r0a694bb re0cdea2 31 31 this.WorkAllTime = WorkAllTime; 32 32 } 33 public int PheadId { get; set; }33 public int? PheadId { get; set; } 34 34 public PharmacyHead PharmacyHead { get; set; } 35 35 } -
FarmatikoData/Models/RequestPharmacyHead.cs
r0a694bb re0cdea2 1 1 using FarmatikoData.Base; 2 using Newtonsoft.Json; 2 3 using System; 3 4 using System.Collections.Generic; … … 13 14 { 14 15 } 15 [Required]16 [JsonProperty Name("PharmacyHead")]16 17 [JsonProperty("PharmacyHead")] 17 18 public PharmacyHead Head { get; set; } 18 [Required]19 [JsonProperty Name("Pharmacy")]19 20 [JsonProperty("Pharmacy")] 20 21 public Pharmacy Pharmacy { get; set; } 21 22 -
FarmatikoServices/FarmatikoServiceInterfaces/IAdminService.cs
r0a694bb re0cdea2 12 12 Task<IEnumerable<PharmacyHead>> GetPharmacyHeads(); 13 13 Task<IEnumerable<RequestPharmacyHead>> GetClaimingRequests(); 14 bool RejectRequest( int Id);14 bool RejectRequest(RequestPharmacyHead req); 15 15 } 16 16 } -
FarmatikoServices/FarmatikoServiceInterfaces/IService.cs
r0a694bb re0cdea2 18 18 HealthFacility GetFacilityJSON(string healthFacility); 19 19 Task<Medicine> GetMedicine(int id); 20 Task<IEnumerable<Medicine >> SearchMedicines(string query);20 Task<IEnumerable<MedicineDTO>> SearchMedicines(string query); 21 21 Task<List<MedicineDTO>> GetMedicines(); 22 Task<Pandemic>GetPandemic();22 Pandemic GetPandemic(); 23 23 Task<List<PharmacyDTO>> GetPharmacies(); 24 Task<IEnumerable<Pharmacy >> SearchPharmacies(string query);24 Task<IEnumerable<PharmacyDTO>> SearchPharmacies(string query); 25 25 Task<Pharmacy> GetPharmacy(int id); 26 26 //POST 27 27 Task AddWorker(HealthcareWorker worker); 28 28 Task AddFacility(HealthFacility healthFacilities); 29 TaskAddPharmacy(Pharmacy pharmacy);29 void AddPharmacy(Pharmacy pharmacy); 30 30 Task<bool> AddPharmacyHead(PharmacyHeadDto pharmacyHead); 31 31 Task AddMedicines(Medicine medicine); -
FarmatikoServices/FarmatikoServices.csproj
r0a694bb re0cdea2 8 8 <PackageReference Include="AngleSharp" Version="0.14.0" /> 9 9 <PackageReference Include="EPPlus" Version="5.4.0" /> 10 <PackageReference Include="GemBox.Spreadsheet" Version="47.0.1095" /> 10 11 <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" /> 11 12 <PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> … … 18 19 </ItemGroup> 19 20 20 <ItemGroup>21 <Folder Include="Services\ExcellDocs\" />22 </ItemGroup>23 24 21 </Project> -
FarmatikoServices/Services/AdminService.cs
r0a694bb re0cdea2 36 36 } 37 37 38 public bool RejectRequest( int Id)38 public bool RejectRequest(RequestPharmacyHead req) 39 39 { 40 if ( Id >= 0)40 if (req != null) 41 41 { 42 _adminRepo.RemoveClaimRequest( Id);42 _adminRepo.RemoveClaimRequest(req); 43 43 return true; 44 44 } -
FarmatikoServices/Services/PHService.cs
r0a694bb re0cdea2 65 65 66 66 phead.Medicines = _repository.GetPHMedicines(phead.Email).ToList(); 67 67 68 var phmeds = await _repository.GetAllPHMedicines(); 69 68 70 List<Medicine> medicines = _repository.GetMedicines().ToList(); 69 70 List<Medicine> PHMedicines = medicines.Where(x => x.Id == phead.Medicines.Select(x => x.MedicineId).Single()).ToList();71 71 72 List<Medicine> PHMedicines = new List<Medicine>(); 73 72 74 List<PharmacyHeadMedicine> list = new List<PharmacyHeadMedicine>(); 73 75 74 75 if (pharmacyHead.Medicines != null || pharmacyHead.Medicines.Count() > 0) 76 77 if (pharmacyHead.Medicines != null && pharmacyHead.Medicines.Count() > 0) 78 { 79 foreach (var med in phead.Medicines) 80 { 81 var medicine = medicines.Where(x => x.Id == med.MedicineId).FirstOrDefault(); 82 if (medicine != null) 83 PHMedicines.Add(medicine); 84 } 85 76 86 if (!pharmacyHead.Medicines.Equals(PHMedicines)) 77 87 { … … 86 96 return; 87 97 } 88 foreach (var med in pharmacyHead.Medicines) 89 { 90 91 PharmacyHeadMedicine PHMObj = phead.Medicines.Select(x => new PharmacyHeadMedicine 98 if (phead.Medicines != null && phead.Medicines.Count() > 0) 99 { 100 foreach (var med in pharmacyHead.Medicines) 92 101 { 93 Id = x.Id, 94 PheadId = x.PheadId, 95 Head = x.Head, 96 MedicineId = x.MedicineId, 97 Medicine = x.Medicine 98 }).Where(x => !x.Medicine.Equals(med)).Single(); 99 if (PHMObj == null || PHMObj == default) 100 break; 101 if (PHMObj.MedicineId == med.Id) 102 list.Add(PHMObj); 103 104 } 102 Medicine medicine = new Medicine() 103 { 104 Name = med.Name, 105 Form = med.Form, 106 Manufacturer = med.Manufacturer, 107 Medicines = med.Medicines, 108 Packaging = med.Packaging, 109 Price = med.Price, 110 Strength = med.Strength, 111 WayOfIssuing = med.WayOfIssuing 112 }; 113 114 PharmacyHeadMedicine phm = new PharmacyHeadMedicine() 115 { 116 PheadId = phead.Id, 117 Head = phead, 118 MedicineId = med.Id, 119 Medicine = medicine 120 }; 121 122 bool ifExists = phead.Medicines.Contains(phm); 123 if (!ifExists) 124 list.Add(phm); 125 126 } 127 } 128 else 129 { 130 foreach (var med in pharmacyHead.Medicines) 131 { 132 PharmacyHead head1 = new PharmacyHead() 133 { 134 Id = pharmacyHead.Id, 135 Name = pharmacyHead.Name, 136 Email = pharmacyHead.Email, 137 Password = pharmacyHead.Password 138 }; 139 PharmacyHeadMedicine phMed = new PharmacyHeadMedicine() 140 { 141 Head = head1, 142 Medicine = med 143 }; 144 list.Add(phMed); 145 } 146 } 147 105 148 106 149 phead.Medicines = list; … … 109 152 110 153 } 111 112 if (pharmacyHead.Pharmacies != null || pharmacyHead.Pharmacies.Count() > 0) 113 { 114 phead.Pharmacies = pharmacyHead.Pharmacies; 115 } 154 } 155 116 156 PharmacyHead head = new PharmacyHead() 117 157 { … … 120 160 Password = pharmacyHead.Password 121 161 }; 162 163 if (pharmacyHead.Pharmacies != null) 164 { 165 if (pharmacyHead.Pharmacies.Count() > 0) 166 { 167 phead.Pharmacies = pharmacyHead.Pharmacies; 168 head.Pharmacies = pharmacyHead.Pharmacies; 169 } 170 } 171 122 172 if (!phead.Equals(head)) 123 173 { -
FarmatikoServices/Services/ProcessJSONService.cs
r0a694bb re0cdea2 1 using FarmatikoData.FarmatikoRepoInterfaces; 2 using FarmatikoData.Models; 3 using System.Collections.Generic; 1 using FarmatikoData.Models; 4 2 using Newtonsoft.Json; 5 3 using Newtonsoft.Json.Linq; … … 13 11 using OfficeOpenXml; 14 12 using System.IO; 15 using Microsoft.VisualBasic; 13 using GemBox.Spreadsheet; 14 using System.Text; 16 15 17 16 namespace FarmatikoServices.Services … … 28 27 } 29 28 //Excel reader 30 private async Task<bool> ReadPharmaciesFromExcel(string Path) 31 { 32 using (var package = new ExcelPackage(new FileInfo(Path))) 33 { 34 var Sheet = package.Workbook.Worksheets[1]; 35 for (int i = 2; i < Sheet.Dimension.End.Row; ++i) 36 { 37 Pharmacy pharmacy = new Pharmacy() 29 private bool ReadPharmaciesFromExcel(string Path) 30 { 31 string path = Directory.GetCurrentDirectory() + @"\ExcellDocs\1.xlsx"; 32 33 FileInfo fileInfo = new FileInfo(path); 34 if (fileInfo != null) 35 { 36 using (var package = new ExcelPackage(fileInfo)) 37 { 38 var Sheet = package.Workbook.Worksheets.First(); 39 //var table = Sheet.Tables.First(); 40 int rowCount = Sheet.Dimension.End.Row; 41 for (int i = 2; i < rowCount; ++i) 38 42 { 39 Name = Sheet.Cells[i, 2].Value.ToString(), 40 Address = Sheet.Cells[i, 3].Value.ToString(), 41 Location = Sheet.Cells[i, 4].Value.ToString(), 42 WorkAllTime = false 43 }; 44 await _service.AddPharmacy(pharmacy); 43 //Console.WriteLine(); 44 Pharmacy pharmacy = new Pharmacy() 45 { 46 Name = Sheet.Cells[i, 2].Value.ToString(), 47 Address = Sheet.Cells[i, 3].Value.ToString(), 48 Location = Sheet.Cells[i, 4].Value.ToString(), 49 WorkAllTime = false 50 }; 51 _service.AddPharmacy(pharmacy); 52 } 45 53 return true; 46 54 } 47 } 55 56 } 57 48 58 return false; 49 } 50 public async void DownloadPharmaciesExcel() 59 60 } 61 public void DownloadPharmaciesExcel() 51 62 { 52 63 try … … 56 67 string pathToSave2 = Directory.GetCurrentDirectory() + @"\ExcellDocs\2.xlsx"; 57 68 var client = new WebClient(); 58 string url1 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/ ce446f5c-e541-46f6-9e8c-67568059cbc6/download/registar-na-apteki-vnatre-vo-mreza-na-fzo-12.08.2020.xlsx";59 string url2 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/a16379b4-ec81-4de7-994d-0ee503d71b55/download/registar-na-apteki-nadvor-od-mreza-na-fzo-12.08.2020.xlsx";69 string url1 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/4806b744-f6f6-42d0-b0f0-d82e66d3b177/download/-.xlsxs"; 70 /*string url2 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/a16379b4-ec81-4de7-994d-0ee503d71b55/download/registar-na-apteki-nadvor-od-mreza-na-fzo-12.08.2020.xlsx";*/ 60 71 Uri uri1 = new Uri(url1); 61 Uri uri2 = new Uri(url2);62 client.DownloadFile (uri1, @pathToSave1);63 client.DownloadFile(uri2, @pathToSave2);64 65 66 bool Success = awaitReadPharmaciesFromExcel(pathToSave1);72 //Uri uri2 = new Uri(url2); 73 client.DownloadFileAsync(uri1, pathToSave1); 74 //client.DownloadFile(uri2, @pathToSave2); 75 76 77 bool Success = ReadPharmaciesFromExcel(pathToSave1); 67 78 _logger.LogInformation(Success.ToString() + "1"); 68 Success = await ReadPharmaciesFromExcel(pathToSave2);69 _logger.LogInformation(Success.ToString() + "2"); 70 } 71 catch (Exception e) 72 { 73 _logger.LogInformation(e.Message); 74 throw new Exception("Cannot process Medicines from Excel.");79 /* Success = await ReadPharmaciesFromExcel(pathToSave2); 80 _logger.LogInformation(Success.ToString() + "2");*/ 81 } 82 catch (Exception e) 83 { 84 _logger.LogInformation(e.Message); 85 throw new Exception("Cannot process Pharmacies from Excel."); 75 86 } 76 87 } -
FarmatikoServices/Services/Service.cs
r0a694bb re0cdea2 3 3 using FarmatikoData.Models; 4 4 using FarmatikoServices.FarmatikoServiceInterfaces; 5 using Microsoft.Extensions.Logging; 6 using Newtonsoft.Json.Linq; 7 using RestSharp; 5 8 using System; 6 9 using System.Collections.Generic; … … 13 16 { 14 17 private readonly IRepository _repository; 15 public Service(IRepository repository) 18 private readonly IPHRepo _phrepo; 19 private readonly ILogger _logger; 20 public Service(IRepository repository, IPHRepo phrepo, ILogger logger) 16 21 { 17 22 _repository = repository; 23 _phrepo = phrepo; 24 _logger = logger; 18 25 } 19 26 … … 76 83 } 77 84 78 public async Task<Pandemic> GetPandemic() 79 { 80 var Pandemic = await _repository.GetPandemic(); 81 return Pandemic; 85 public Pandemic GetPandemic() 86 { 87 //var Pandemic = await _repository.GetPandemic(); 88 89 try 90 { 91 var Date = DateTime.UtcNow.ToString("yyyy-MM-dd"); 92 var client = new RestClient($"https://api.covid19tracking.narrativa.com/api/{Date}/country/north_macedonia"); 93 var response = client.Execute(new RestRequest()); 94 string original = response.Content; 95 var jsonResponsePandemic = JObject.Parse(original); 96 if (!jsonResponsePandemic.ContainsKey("total")) 97 { 98 Date = DateTime.UtcNow.AddDays(-1).ToString("yyyy-MM-dd"); 99 client = new RestClient($"https://api.covid19tracking.narrativa.com/api/{Date}/country/north_macedonia"); 100 response = client.Execute(new RestRequest()); 101 original = response.Content; 102 jsonResponsePandemic = JObject.Parse(original); 103 if (!jsonResponsePandemic.ContainsKey("total")) 104 { 105 Date = DateTime.UtcNow.AddDays(-2).ToString("yyyy-MM-dd"); 106 client = new RestClient($"https://api.covid19tracking.narrativa.com/api/{Date}/country/north_macedonia"); 107 response = client.Execute(new RestRequest()); 108 original = response.Content; 109 jsonResponsePandemic = JObject.Parse(original); 110 } 111 } 112 var global = JObject.Parse(jsonResponsePandemic.GetValue("total").ToString()); 113 var TotalConfirmed = long.Parse(global.GetValue("today_confirmed").ToString()); 114 var TotalDeaths = long.Parse(global.GetValue("today_deaths").ToString()); 115 var TotalRecovered = long.Parse(global.GetValue("today_new_recovered").ToString()); 116 117 var mk = JObject.Parse(jsonResponsePandemic.GetValue("dates").ToString()); 118 119 var date = JObject.Parse(mk.GetValue(Date).ToString()); 120 var country = JObject.Parse(date.GetValue("countries").ToString()); 121 var mkd = JObject.Parse(country.GetValue("North Macedonia").ToString()); 122 dynamic objP = mkd; 123 var TotalMk = Int32.Parse(objP.GetValue("today_confirmed").ToString()); 124 var TotalDeathsMK = Int32.Parse(objP.GetValue("today_deaths").ToString()); 125 var TotalRecoveredMK = Int32.Parse(objP.GetValue("today_recovered").ToString()); 126 var NewMK = Int32.Parse(objP.GetValue("today_new_confirmed").ToString()); 127 128 var Name = "Coronavirus"; 129 var ActiveMk = TotalMk - (TotalRecoveredMK + TotalDeathsMK); 130 var ActiveGlobal = TotalConfirmed - (TotalRecovered + TotalDeaths); 131 132 Pandemic pandemic = new Pandemic(Name, TotalMk, ActiveMk, TotalDeathsMK, NewMK, TotalConfirmed, TotalDeaths, ActiveGlobal); 133 return pandemic; 134 } 135 catch (Exception e) 136 { 137 _logger.LogInformation(e.Message); 138 } 139 return null; 82 140 } 83 141 … … 86 144 var Pharmacies = await _repository.GetPharmacies(); 87 145 List<PharmacyDTO> pharmacies = new List<PharmacyDTO>(); 88 146 89 147 foreach(var pharm in Pharmacies) 90 148 { … … 124 182 } 125 183 126 public async Task<IEnumerable<Medicine >> SearchMedicines(string query)184 public async Task<IEnumerable<MedicineDTO>> SearchMedicines(string query) 127 185 { 128 186 var SearchQuery = await _repository.SearchMedicines(query); 129 return SearchQuery; 130 } 131 132 public async Task<IEnumerable<Pharmacy>> SearchPharmacies(string query) 187 List<MedicineDTO> list = new List<MedicineDTO>(); 188 var listPHMedicines = await _repository.GetAllPHMedicines(); 189 List<string> headNames = new List<string>(); 190 List<PharmacyHead> heads = new List<PharmacyHead>(); 191 foreach (var med in SearchQuery) 192 { 193 var meds = listPHMedicines.Where(x => x.MedicineId == med.Id).ToList(); 194 if (meds != null) 195 { 196 heads = meds.Select(x => x.Head).ToList(); 197 } 198 if (heads != null) 199 headNames = heads?.Select(x => x?.Name).ToList(); 200 MedicineDTO medicine = new MedicineDTO() 201 { 202 Name = med.Name, 203 Manufacturer = med.Manufacturer, 204 Packaging = med.Packaging, 205 Form = med.Form, 206 Price = med.Price, 207 Strength = med.Strength, 208 WayOfIssuing = med.WayOfIssuing, 209 HeadNames = headNames 210 }; 211 212 list.Add(medicine); 213 headNames = new List<string>(); 214 } 215 216 return list; 217 } 218 219 public async Task<IEnumerable<PharmacyDTO>> SearchPharmacies(string query) 133 220 { 134 221 var SearchQuery = await _repository.SearchPharmacies(query); 135 return SearchQuery; 222 List<PharmacyDTO> pharmacies = new List<PharmacyDTO>(); 223 var heads = await _phrepo.GetPharmacyHeadInfo(); 224 225 foreach (var pharm in SearchQuery) 226 { 227 PharmacyDTO pharmacyDTO = new PharmacyDTO() 228 { 229 Name = pharm.Name, 230 Location = pharm.Location, 231 Address = pharm.Address, 232 WorkAllTime = pharm.WorkAllTime 233 }; 234 235 foreach(var head in heads.ToList()) 236 { 237 if (head.Pharmacies.Contains(pharm)) 238 { 239 pharmacyDTO.HeadName = head.Name; 240 break; 241 } 242 } 243 244 pharmacies.Add(pharmacyDTO); 245 } 246 return pharmacies; 136 247 } 137 248 … … 166 277 } 167 278 // Samo PharmacyHead i Admin imaat pristap 168 public async TaskAddPharmacy(Pharmacy pharmacy)279 public void AddPharmacy(Pharmacy pharmacy) 169 280 { 170 281 if (pharmacy != null) 171 await_repository.AddPharmacy(pharmacy);282 _repository.AddPharmacy(pharmacy); 172 283 else throw new Exception("Pharmacy is null"); 173 284 } 174 285 175 286 // Ovaa kontrola ja ima samo admin 176 public async Task<User> MakeUser(PharmacyHead head) 177 { 178 User user = new User() 179 { 180 Name = head.Name, 181 Password = head.Password, 182 Email = head.Email, 183 UserRole = User.Role.PharmacyHead 184 }; 185 bool Success = await _repository.AddUser(user); 186 if (!Success) 187 return null; 188 return user; 189 } 287 190 288 public async Task<bool> AddPharmacyHead(PharmacyHeadDto pharmacyHead) 191 289 { … … 198 296 Password = pharmacyHead.Password 199 297 }; 200 var user = await MakeUser(phead); 298 User user = new User() 299 { 300 Name = phead.Name, 301 Password = phead.Password, 302 Email = phead.Email, 303 UserRole = User.Role.PharmacyHead 304 }; 201 305 if (user is null) 202 306 { 203 307 return false; 204 308 } 205 var users = _repository.GetUsers();206 var thisUser = users.Where(usr => usr.Value.Email.Equals(user.Email)).Select(x => x.Value).FirstOrDefault();207 309 User user1 = new User() 208 310 { 209 Name = thisUser.Name,210 Password = thisUser.Password,211 Email = thisUser.Email,212 UserRole = thisUser.UserRole311 Name = user.Name, 312 Password = user.Password, 313 Email = user.Email, 314 UserRole = user.UserRole 213 315 }; 214 316 phead.User = user1;
Note:
See TracChangeset
for help on using the changeset viewer.