Changeset db484c9
- Timestamp:
- 01/26/21 10:33:09 (4 years ago)
- Branches:
- master
- Children:
- 7d80751
- Parents:
- 8e74e2f
- Files:
-
- 1 added
- 17 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
Farmatiko/Controllers/AdminController.cs
r8e74e2f rdb484c9 3 3 using System.Linq; 4 4 using System.Threading.Tasks; 5 using FarmatikoData.DTOs; 5 6 using FarmatikoData.Models; 6 7 using FarmatikoServices.FarmatikoServiceInterfaces; … … 46 47 { 47 48 await _service.AddPharmacyHead(pharmacyHead); 48 return Ok( );49 return Ok("Pharmacy added."); 49 50 } 50 51 … … 65 66 [HttpPost] 66 67 [Route("api/pharmacyhead/{Id}")] 67 public async Task<IActionResult> ApproveRequest([FromRoute]int Id, [FromBody]PharmacyHead pharmacyHead)68 public async Task<IActionResult> ApproveRequest([FromRoute]int Id, [FromBody]PharmacyHeadDto pharmacyHead) 68 69 { 69 int id = Id;70 70 await _phservice.UpdatePharmacyHead(pharmacyHead); 71 71 return Ok(); -
Farmatiko/Controllers/FarmatikoController.cs
r8e74e2f rdb484c9 24 24 { 25 25 //_JSONservice.DownloadPharmaciesExcel(); 26 _JSONservice.GetProcessedHealthcareWorkersFromJSON();26 //_JSONservice.GetProcessedHealthcareWorkersFromJSON(); 27 27 //_JSONservice.GetProcessedHealthFacilitiesFromJSON(); 28 28 //_JSONservice.GetProcessedMedicinesFromJSON(); -
Farmatiko/Controllers/LoginController.cs
r8e74e2f rdb484c9 82 82 public ActionResult Logout() 83 83 { 84 // optionally "revoke" JWT token on the server side --> add the current token to a block-list85 // https://github.com/auth0/node-jsonwebtoken/issues/37586 87 84 var userName = User.Identity.Name; 88 85 _jwtAuthManager.RemoveRefreshTokenByUserName(userName); -
Farmatiko/Controllers/PharmacyHeadController.cs
r8e74e2f rdb484c9 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; … … 19 20 20 21 //GET 21 /* 22 [HttpGet] 23 [Route("api/pharmacyhead")] 24 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo() 25 { 26 var PHeads = await _PHService.GetPharmacyHeadInfo(); 27 return PHeads; 28 }*/ 29 22 30 23 [HttpGet] 31 24 [Route("api/pharmacyhead/{Id}")] … … 36 29 } 37 30 //POST 38 /* 39 [HttpPost] 40 [Route("api/pharmacyhead/add")] 41 public async Task<IActionResult> AddPharmacyHead([FromBody] PharmacyHead pharmacyHead) 42 { 43 bool Success = await _PHService.Add(pharmacyHead); 44 return Ok(Success); 45 }*/ 46 47 /*[HttpPost] 48 [Route("api/pharmacyhead/login")] 49 public async Task<int> Login([FromBody]PharmacyHead pharmacyHead) 50 { 51 return await _PHService.Login(pharmacyHead); 52 }*/ 31 53 32 [HttpPut] 54 33 [Route("api/pharmacyhead/update")] 55 public async Task UpdatePharmacyHead([FromBody] PharmacyHeadpharmacyHead)34 public async Task<IActionResult> UpdatePharmacyHead([FromBody] PharmacyHeadDto pharmacyHead) 56 35 { 57 36 await _PHService.UpdatePharmacyHead(pharmacyHead); 37 return Ok(); 58 38 } 59 39 [HttpPost] -
FarmatikoData/FarmatikoDataContext.cs
r8e74e2f rdb484c9 9 9 10 10 11 public virtualDbSet<HealthFacility> HealthFacilities { get; set; }12 public virtualDbSet<HealthcareWorker> HealthcareWorkers { get; set; }13 public virtualDbSet<Pharmacy> Pharmacies { get; set; }14 public virtualDbSet<PharmacyHead> PharmacyHeads { get; set; }15 public virtualDbSet<Pandemic> Pandemics { get; set; }16 public virtualDbSet<Medicine> Medicines { get; set; }17 public virtualDbSet<RequestPharmacyHead> PHRequests { get; set; }18 public virtualDbSet<User> Users { get; set; }19 public virtualDbSet<PharmacyHeadMedicine> PharmacyHeadMedicines { get; set; }11 public DbSet<HealthFacility> HealthFacilities { get; set; } 12 public DbSet<HealthcareWorker> HealthcareWorkers { get; set; } 13 public DbSet<Pharmacy> Pharmacies { get; set; } 14 public DbSet<PharmacyHead> PharmacyHeads { get; set; } 15 public DbSet<Pandemic> Pandemics { get; set; } 16 public DbSet<Medicine> Medicines { get; set; } 17 public DbSet<RequestPharmacyHead> PHRequests { get; set; } 18 public DbSet<User> Users { get; set; } 19 public DbSet<PharmacyHeadMedicine> PharmacyHeadMedicines { get; set; } 20 20 21 21 protected override void OnModelCreating(ModelBuilder modelBuilder) … … 31 31 modelBuilder.Entity<Pharmacy>() 32 32 .ToTable("Pharmacies"); 33 34 modelBuilder.Entity<PharmacyHeadMedicine>() 35 .ToTable("PharmacyHeadMedicines"); 36 37 modelBuilder.Entity<RequestPharmacyHead>() 38 .ToTable("PHRequests"); 33 39 34 40 modelBuilder.Entity<Medicine>() … … 52 58 .HasIdentityOptions(startValue: 1); 53 59 54 modelBuilder.Entity<User>()60 /*modelBuilder.Entity<User>() 55 61 .Property(x => x.Id) 56 62 .HasIdentityOptions(startValue: 1); … … 58 64 modelBuilder.Entity<PharmacyHeadMedicine>() 59 65 .HasKey(phm => new { phm.PheadId, phm.MedicineId }); 60 modelBuilder.Entity<PharmacyHeadMedicine>()61 .HasOne(ph => ph.Head)62 .WithMany(m => m.PHMedicineList)63 .HasForeignKey(k => k.PheadId);64 65 modelBuilder.Entity<PharmacyHeadMedicine>()66 .HasOne(m => m.Medicine)67 .WithMany(ml => ml.MedicineList)68 .HasForeignKey(k => k.MedicineId);69 66 70 67 modelBuilder.Entity<PharmacyHead>() 71 .HasMany (p => p.PharmaciesList)72 .WithOne( h => h.PHead)73 .HasForeignKey( k => k.PheadId);68 .HasMany<Pharmacy>(p => p.Pharmacy) 69 .WithOne(p => p.PharmacyHead) 70 .HasForeignKey(); 74 71 75 76 72 modelBuilder.Entity<Pharmacy>() 73 .HasOne<PharmacyHead>(p => p.PharmacyHead) 74 .WithMany(p => p.Pharmacy); 75 */ 76 77 77 base.OnModelCreating(modelBuilder); 78 78 } -
FarmatikoData/FarmatikoRepo/AdminRepo.cs
r8e74e2f rdb484c9 27 27 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeads() 28 28 { 29 var PHeads = await _context.PharmacyHeads.OrderBy(x => x.Name).ToListAsync(); 29 var PHeads = await _context.PharmacyHeads 30 .Include(x => x.Medicines) 31 .Include(x => x.Pharmacies) 32 .OrderBy(x => x.Name) 33 .ToListAsync(); 30 34 return PHeads; 31 35 } 32 36 //POST 33 public void RemoveClaimRequest(int Id)37 public async void RemoveClaimRequest(int Id) 34 38 { 35 39 var req = _context.PHRequests.Where(x => x.Id == Id).FirstOrDefault(); 36 40 _context.PHRequests.Remove(req); 37 _context.SaveChanges();41 await _context.SaveChangesAsync(); 38 42 } 39 43 } -
FarmatikoData/FarmatikoRepo/PHRepo.cs
r8e74e2f rdb484c9 24 24 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo() 25 25 { 26 var PHeadInfo = await _context.PharmacyHeads.Take(10).Where(x => x.DeletedOn == null) 26 var PHeadInfo = await _context.PharmacyHeads.Take(10) 27 .Where(x => x.DeletedOn == null) 27 28 .Select(x => new PharmacyHead 28 29 { … … 31 32 Email = x.Email, 32 33 Password = x.Password, 33 MedicineList = x.MedicineList, 34 PharmaciesList = x.PharmaciesList 34 Pharmacies = x.Pharmacies, 35 Medicines = x.Medicines 36 35 37 }).ToListAsync(); 36 38 return PHeadInfo; … … 41 43 var Phead = await _context.PharmacyHeads.Where(x => x.Email == pharmacyHead.Email).FirstOrDefaultAsync(); 42 44 var EditedPHead = await _context.PharmacyHeads.AsNoTracking<PharmacyHead>().Where(x => x.Email == pharmacyHead.Email).FirstOrDefaultAsync(); 43 EditedPHead.Email = pharmacyHead.Email; 44 EditedPHead.Name = pharmacyHead.Name; 45 EditedPHead.Password = pharmacyHead.Password; 46 /*if (pharmacyHead.MedicineList.Count() == 0) 47 pharmacyHead.MedicineList = null;*/ 48 EditedPHead.MedicineList = pharmacyHead.MedicineList; 49 EditedPHead.PharmaciesList = pharmacyHead.PharmaciesList; 50 EditedPHead.PHMedicineList = pharmacyHead.PHMedicineList; 51 //_context.Entry<PharmacyHead>(Phead).State = EntityState.Detached; 52 //Phead = EditedPHead; 45 46 if (!EditedPHead.Email.Equals(pharmacyHead.Email)) 47 EditedPHead.Email = pharmacyHead.Email; 48 49 if (!EditedPHead.Name.Equals(pharmacyHead.Name)) 50 EditedPHead.Name = pharmacyHead.Name; 51 52 if (!EditedPHead.Password.Equals(pharmacyHead.Password)) 53 EditedPHead.Password = pharmacyHead.Password; 54 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 53 61 await _context.SaveChangesAsync(); 54 62 } … … 81 89 public PharmacyHead GetPharmacyHeadByUserName(string userName) 82 90 { 91 92 83 93 var PHead = _context.PharmacyHeads 84 94 .Where(x => x.Email.Equals(userName)) 85 .FirstOrDefault(); 95 .Select(x => new PharmacyHead 96 { 97 Email = x.Email, 98 Name = x.Name, 99 Password = x.Password, 100 Medicines = x.Medicines, 101 Pharmacies = x.Pharmacies 102 }).FirstOrDefault(); 103 104 86 105 87 106 return PHead; … … 90 109 public List<PharmacyHeadMedicine> GetPharmacyHeadMedicines(string email) 91 110 { 92 /*var meds = _context.Medicines.ToList();93 var medicines = Medicines;*/94 111 var Phead = _context.PharmacyHeads.Where(x => x.Email.Equals(email)).FirstOrDefault(); 95 var Medicines = _context.PharmacyHeadMedicines.Where(x => x.PheadId == Phead.Id).ToList(); 96 /*.Select(x => x.Head.MedicineList) 97 .SelectMany(mList => mList) 98 .ToList();*/ 112 var Medicines = _context.PharmacyHeadMedicines.Select(x => new PharmacyHeadMedicine 113 { 114 PheadId = x.PheadId, 115 Head = x.Head, 116 MedicineId = x.MedicineId, 117 Medicine = x.Medicine 118 }).ToList(); 119 if (Medicines == null || Medicines == default) 120 Medicines = null; 121 var meds = Medicines.Where(x => x.PheadId == Phead.Id).ToList(); 99 122 100 101 return Medicines; 123 return meds; 102 124 } 103 125 -
FarmatikoData/FarmatikoRepo/Repository.cs
r8e74e2f rdb484c9 86 86 var SearchQuery = await _context.HealthFacilities 87 87 .Where(x => x.Name.Contains(query)) 88 .OrderBy(x => x.Name).T ake(3).ToListAsync();88 .OrderBy(x => x.Name).ToListAsync(); 89 89 90 90 return SearchQuery; … … 95 95 var SearchQuery = await _context.Medicines 96 96 .Where(x => x.Name.Contains(query)) 97 .OrderBy(x => x.Name).T ake(5).ToListAsync();97 .OrderBy(x => x.Name).ToListAsync(); 98 98 99 99 return SearchQuery; … … 104 104 var SearchQuery = await _context.Pharmacies.Take(5) 105 105 .Where(x => x.Name.Contains(query)) 106 .OrderBy(x => x.Name).T ake(5).ToListAsync();106 .OrderBy(x => x.Name).ToListAsync(); 107 107 108 108 return SearchQuery; … … 113 113 var SearchQuery = await _context.HealthcareWorkers.Take(5) 114 114 .Where(x => x.Name.Contains(query)) 115 .OrderBy(x => x.Name).T ake(5).ToListAsync();115 .OrderBy(x => x.Name).ToListAsync(); 116 116 117 117 return SearchQuery; … … 170 170 Facility.Phone = healthFacility.Phone; 171 171 Facility.Type = healthFacility.Type; 172 _context.SaveChanges();172 await _context.SaveChangesAsync(); 173 173 } 174 174 175 175 public async Task RemoveMedicine(Medicine medicine) 176 176 { 177 await Task.Run(() => _context.Medicines.Remove(medicine));178 _context.SaveChanges();177 _context.Medicines.Remove(medicine); 178 await _context.SaveChangesAsync(); 179 179 } 180 180 … … 190 190 Pandemic.TotalGlobal = pandemic.TotalGlobal; 191 191 Pandemic.TotalMK = pandemic.TotalMK; 192 _context.SaveChanges();192 await _context.SaveChangesAsync(); 193 193 } 194 194 195 195 public async Task RemovePharmacy(Pharmacy pharmacy) 196 196 { 197 await Task.Run(() => _context.Pharmacies.Remove(pharmacy));198 _context.SaveChanges();197 _context.Pharmacies.Remove(pharmacy); 198 await _context.SaveChangesAsync(); 199 199 } 200 200 //not impl … … 211 211 Pharmacy.WorkAllTime = pharmacy.WorkAllTime; 212 212 Pharmacy.Address = pharmacy.Address; 213 _context.SaveChanges();214 } 215 // ke vidime213 await _context.SaveChangesAsync(); 214 } 215 //not implemented, not needed 216 216 public Task UpdateMedicine(Medicine medicine) 217 217 { … … 223 223 var PHead = await _context.PharmacyHeads.Where(x => x.Id == Id).FirstOrDefaultAsync(); 224 224 PHead.DeletedOn = DateTime.UtcNow; 225 _context.SaveChanges();225 await _context.SaveChangesAsync(); 226 226 } 227 227 … … 236 236 UserRole = x.UserRole 237 237 }); 238 238 239 return users; 239 240 } … … 257 258 Price = x.Price, 258 259 Packaging = x.Packaging, 259 Medicine List = x.MedicineList260 Medicines = x.Medicines 260 261 261 262 }).ToList(); … … 266 267 { 267 268 var head = _context.PharmacyHeads.Where(x => x.Email.Equals(email)).FirstOrDefault(); 268 var phmeds = _context.PharmacyHeadMedicines.Where(x => x.PheadId == head.Id). ToList();269 var phmeds = _context.PharmacyHeadMedicines.Where(x => x.PheadId == head.Id).Include(x => x.Medicine).ToList(); 269 270 return phmeds; 270 271 } -
FarmatikoData/Migrations/20210124191844_InitialMigration.Designer.cs
r8e74e2f rdb484c9 11 11 { 12 12 [DbContext(typeof(FarmatikoDataContext))] 13 [Migration("202 01115222819_InitialMigration")]13 [Migration("20210124191844_InitialMigration")] 14 14 partial class InitialMigration 15 15 { … … 124 124 .HasColumnType("text"); 125 125 126 b.Property<int?>("PharmacyHeadId")127 .HasColumnType("integer");128 129 126 b.Property<float>("Price") 130 127 .HasColumnType("real"); … … 140 137 b.HasKey("Id"); 141 138 142 b.HasIndex("PharmacyHeadId");143 144 139 b.ToTable("Medicines"); 145 140 }); … … 214 209 .HasColumnType("text"); 215 210 211 b.Property<int?>("PharmacyHeadId") 212 .HasColumnType("integer"); 213 216 214 b.Property<int>("PheadId") 217 215 .HasColumnType("integer"); … … 222 220 b.HasKey("Id"); 223 221 224 b.HasIndex("Ph eadId");222 b.HasIndex("PharmacyHeadId"); 225 223 226 224 b.ToTable("Pharmacies"); … … 253 251 .HasColumnType("text"); 254 252 255 b.HasKey("Id"); 253 b.Property<int?>("UserId") 254 .HasColumnType("integer"); 255 256 b.HasKey("Id"); 257 258 b.HasIndex("UserId"); 256 259 257 260 b.ToTable("PharmacyHeads"); … … 260 263 modelBuilder.Entity("FarmatikoData.Models.PharmacyHeadMedicine", b => 261 264 { 265 b.Property<int>("Id") 266 .ValueGeneratedOnAdd() 267 .HasColumnType("integer") 268 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'") 269 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 270 271 b.Property<DateTime>("CreatedOn") 272 .HasColumnType("timestamp without time zone"); 273 274 b.Property<DateTime?>("DeletedOn") 275 .HasColumnType("timestamp without time zone"); 276 277 b.Property<int?>("HeadId") 278 .HasColumnType("integer"); 279 280 b.Property<int>("MedicineId") 281 .HasColumnType("integer"); 282 262 283 b.Property<int>("PheadId") 263 284 .HasColumnType("integer"); 264 285 265 b.Property<int>("MedicineId") 266 .HasColumnType("integer"); 267 268 b.Property<DateTime>("CreatedOn") 269 .HasColumnType("timestamp without time zone"); 270 271 b.Property<DateTime?>("DeletedOn") 272 .HasColumnType("timestamp without time zone"); 273 274 b.Property<int>("Id") 275 .HasColumnType("integer") 276 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'"); 277 278 b.HasKey("PheadId", "MedicineId"); 286 b.HasKey("Id"); 287 288 b.HasIndex("HeadId"); 279 289 280 290 b.HasIndex("MedicineId"); … … 317 327 .ValueGeneratedOnAdd() 318 328 .HasColumnType("integer") 319 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'")320 329 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 321 330 … … 355 364 }); 356 365 357 modelBuilder.Entity("FarmatikoData.Models. Medicine", b =>358 { 359 b.HasOne("FarmatikoData.Models.PharmacyHead", null)360 .WithMany(" MedicineList")366 modelBuilder.Entity("FarmatikoData.Models.Pharmacy", b => 367 { 368 b.HasOne("FarmatikoData.Models.PharmacyHead", "PharmacyHead") 369 .WithMany("Pharmacies") 361 370 .HasForeignKey("PharmacyHeadId"); 362 371 }); 363 372 364 modelBuilder.Entity("FarmatikoData.Models.Pharmacy", b => 365 { 366 b.HasOne("FarmatikoData.Models.PharmacyHead", "PHead") 367 .WithMany("PharmaciesList") 368 .HasForeignKey("PheadId") 369 .OnDelete(DeleteBehavior.Cascade) 370 .IsRequired(); 373 modelBuilder.Entity("FarmatikoData.Models.PharmacyHead", b => 374 { 375 b.HasOne("FarmatikoData.Models.User", "User") 376 .WithMany() 377 .HasForeignKey("UserId"); 371 378 }); 372 379 373 380 modelBuilder.Entity("FarmatikoData.Models.PharmacyHeadMedicine", b => 374 381 { 382 b.HasOne("FarmatikoData.Models.PharmacyHead", "Head") 383 .WithMany("Medicines") 384 .HasForeignKey("HeadId"); 385 375 386 b.HasOne("FarmatikoData.Models.Medicine", "Medicine") 376 .WithMany("Medicine List")387 .WithMany("Medicines") 377 388 .HasForeignKey("MedicineId") 378 .OnDelete(DeleteBehavior.Cascade)379 .IsRequired();380 381 b.HasOne("FarmatikoData.Models.PharmacyHead", "Head")382 .WithMany("PHMedicineList")383 .HasForeignKey("PheadId")384 389 .OnDelete(DeleteBehavior.Cascade) 385 390 .IsRequired(); -
FarmatikoData/Migrations/20210124191844_InitialMigration.cs
r8e74e2f rdb484c9 15 15 Id = table.Column<int>(nullable: false) 16 16 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), 17 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"),17 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 18 18 DeletedOn = table.Column<DateTime>(nullable: true), 19 19 Name = table.Column<string>(nullable: false), … … 27 27 { 28 28 table.PrimaryKey("PK_HealthFacilities", x => x.Id); 29 }); 30 31 migrationBuilder.CreateTable( 32 name: "Medicines", 33 columns: table => new 34 { 35 Id = table.Column<int>(nullable: false) 36 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), 37 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 38 DeletedOn = table.Column<DateTime>(nullable: true), 39 Name = table.Column<string>(nullable: false), 40 Strength = table.Column<string>(nullable: false), 41 Form = table.Column<string>(nullable: true), 42 WayOfIssuing = table.Column<string>(nullable: false), 43 Manufacturer = table.Column<string>(nullable: false), 44 Price = table.Column<float>(nullable: false), 45 Packaging = table.Column<string>(nullable: true) 46 }, 47 constraints: table => 48 { 49 table.PrimaryKey("PK_Medicines", x => x.Id); 29 50 }); 30 51 … … 52 73 53 74 migrationBuilder.CreateTable( 54 name: "PharmacyHeads",55 columns: table => new56 {57 Id = table.Column<int>(nullable: false)58 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),59 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"),60 DeletedOn = table.Column<DateTime>(nullable: true),61 Email = table.Column<string>(nullable: false),62 Name = table.Column<string>(nullable: false),63 Password = table.Column<string>(nullable: false)64 },65 constraints: table =>66 {67 table.PrimaryKey("PK_PharmacyHeads", x => x.Id);68 });69 70 migrationBuilder.CreateTable(71 75 name: "Users", 72 76 columns: table => new … … 111 115 112 116 migrationBuilder.CreateTable( 113 name: "Medicines", 114 columns: table => new 115 { 116 Id = table.Column<int>(nullable: false) 117 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), 118 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 119 DeletedOn = table.Column<DateTime>(nullable: true), 120 Name = table.Column<string>(nullable: false), 121 Strength = table.Column<string>(nullable: false), 122 Form = table.Column<string>(nullable: true), 123 WayOfIssuing = table.Column<string>(nullable: false), 124 Manufacturer = table.Column<string>(nullable: false), 125 Price = table.Column<float>(nullable: false), 126 Packaging = table.Column<string>(nullable: true), 127 PharmacyHeadId = table.Column<int>(nullable: true) 128 }, 129 constraints: table => 130 { 131 table.PrimaryKey("PK_Medicines", x => x.Id); 132 table.ForeignKey( 133 name: "FK_Medicines_PharmacyHeads_PharmacyHeadId", 134 column: x => x.PharmacyHeadId, 135 principalTable: "PharmacyHeads", 117 name: "PharmacyHeads", 118 columns: table => new 119 { 120 Id = table.Column<int>(nullable: false) 121 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), 122 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 123 DeletedOn = table.Column<DateTime>(nullable: true), 124 Email = table.Column<string>(nullable: false), 125 Name = table.Column<string>(nullable: false), 126 Password = table.Column<string>(nullable: false), 127 UserId = table.Column<int>(nullable: true) 128 }, 129 constraints: table => 130 { 131 table.PrimaryKey("PK_PharmacyHeads", x => x.Id); 132 table.ForeignKey( 133 name: "FK_PharmacyHeads_Users_UserId", 134 column: x => x.UserId, 135 principalTable: "Users", 136 136 principalColumn: "Id", 137 137 onDelete: ReferentialAction.Restrict); … … 150 150 Address = table.Column<string>(nullable: false), 151 151 WorkAllTime = table.Column<bool>(nullable: false), 152 PheadId = table.Column<int>(nullable: false) 152 PheadId = table.Column<int>(nullable: false), 153 PharmacyHeadId = table.Column<int>(nullable: true) 153 154 }, 154 155 constraints: table => … … 156 157 table.PrimaryKey("PK_Pharmacies", x => x.Id); 157 158 table.ForeignKey( 158 name: "FK_Pharmacies_PharmacyHeads_Ph eadId",159 column: x => x.Ph eadId,159 name: "FK_Pharmacies_PharmacyHeads_PharmacyHeadId", 160 column: x => x.PharmacyHeadId, 160 161 principalTable: "PharmacyHeads", 161 162 principalColumn: "Id", 162 onDelete: ReferentialAction. Cascade);163 onDelete: ReferentialAction.Restrict); 163 164 }); 164 165 … … 167 168 columns: table => new 168 169 { 170 Id = table.Column<int>(nullable: false) 171 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), 172 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 173 DeletedOn = table.Column<DateTime>(nullable: true), 169 174 PheadId = table.Column<int>(nullable: false), 170 MedicineId = table.Column<int>(nullable: false), 171 Id = table.Column<int>(nullable: false), 172 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 173 DeletedOn = table.Column<DateTime>(nullable: true) 174 }, 175 constraints: table => 176 { 177 table.PrimaryKey("PK_PharmacyHeadMedicines", x => new { x.PheadId, x.MedicineId }); 175 HeadId = table.Column<int>(nullable: true), 176 MedicineId = table.Column<int>(nullable: false) 177 }, 178 constraints: table => 179 { 180 table.PrimaryKey("PK_PharmacyHeadMedicines", x => x.Id); 181 table.ForeignKey( 182 name: "FK_PharmacyHeadMedicines_PharmacyHeads_HeadId", 183 column: x => x.HeadId, 184 principalTable: "PharmacyHeads", 185 principalColumn: "Id", 186 onDelete: ReferentialAction.Restrict); 178 187 table.ForeignKey( 179 188 name: "FK_PharmacyHeadMedicines_Medicines_MedicineId", … … 182 191 principalColumn: "Id", 183 192 onDelete: ReferentialAction.Cascade); 184 table.ForeignKey(185 name: "FK_PharmacyHeadMedicines_PharmacyHeads_PheadId",186 column: x => x.PheadId,187 principalTable: "PharmacyHeads",188 principalColumn: "Id",189 onDelete: ReferentialAction.Cascade);190 193 }); 191 194 … … 224 227 225 228 migrationBuilder.CreateIndex( 226 name: "IX_ Medicines_PharmacyHeadId",227 table: " Medicines",229 name: "IX_Pharmacies_PharmacyHeadId", 230 table: "Pharmacies", 228 231 column: "PharmacyHeadId"); 229 232 230 233 migrationBuilder.CreateIndex( 231 name: "IX_Pharmac ies_PheadId",232 table: "Pharmac ies",233 column: " PheadId");234 name: "IX_PharmacyHeadMedicines_HeadId", 235 table: "PharmacyHeadMedicines", 236 column: "HeadId"); 234 237 235 238 migrationBuilder.CreateIndex( … … 237 240 table: "PharmacyHeadMedicines", 238 241 column: "MedicineId"); 242 243 migrationBuilder.CreateIndex( 244 name: "IX_PharmacyHeads_UserId", 245 table: "PharmacyHeads", 246 column: "UserId"); 239 247 240 248 migrationBuilder.CreateIndex( … … 264 272 265 273 migrationBuilder.DropTable( 274 name: "HealthFacilities"); 275 276 migrationBuilder.DropTable( 277 name: "Medicines"); 278 279 migrationBuilder.DropTable( 280 name: "Pharmacies"); 281 282 migrationBuilder.DropTable( 283 name: "PharmacyHeads"); 284 285 migrationBuilder.DropTable( 266 286 name: "Users"); 267 268 migrationBuilder.DropTable(269 name: "HealthFacilities");270 271 migrationBuilder.DropTable(272 name: "Medicines");273 274 migrationBuilder.DropTable(275 name: "Pharmacies");276 277 migrationBuilder.DropTable(278 name: "PharmacyHeads");279 287 } 280 288 } -
FarmatikoData/Migrations/FarmatikoDataContextModelSnapshot.cs
r8e74e2f rdb484c9 122 122 .HasColumnType("text"); 123 123 124 b.Property<int?>("PharmacyHeadId")125 .HasColumnType("integer");126 127 124 b.Property<float>("Price") 128 125 .HasColumnType("real"); … … 138 135 b.HasKey("Id"); 139 136 140 b.HasIndex("PharmacyHeadId");141 142 137 b.ToTable("Medicines"); 143 138 }); … … 212 207 .HasColumnType("text"); 213 208 209 b.Property<int?>("PharmacyHeadId") 210 .HasColumnType("integer"); 211 214 212 b.Property<int>("PheadId") 215 213 .HasColumnType("integer"); … … 220 218 b.HasKey("Id"); 221 219 222 b.HasIndex("Ph eadId");220 b.HasIndex("PharmacyHeadId"); 223 221 224 222 b.ToTable("Pharmacies"); … … 251 249 .HasColumnType("text"); 252 250 253 b.HasKey("Id"); 251 b.Property<int?>("UserId") 252 .HasColumnType("integer"); 253 254 b.HasKey("Id"); 255 256 b.HasIndex("UserId"); 254 257 255 258 b.ToTable("PharmacyHeads"); … … 258 261 modelBuilder.Entity("FarmatikoData.Models.PharmacyHeadMedicine", b => 259 262 { 263 b.Property<int>("Id") 264 .ValueGeneratedOnAdd() 265 .HasColumnType("integer") 266 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'") 267 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 268 269 b.Property<DateTime>("CreatedOn") 270 .HasColumnType("timestamp without time zone"); 271 272 b.Property<DateTime?>("DeletedOn") 273 .HasColumnType("timestamp without time zone"); 274 275 b.Property<int?>("HeadId") 276 .HasColumnType("integer"); 277 278 b.Property<int>("MedicineId") 279 .HasColumnType("integer"); 280 260 281 b.Property<int>("PheadId") 261 282 .HasColumnType("integer"); 262 283 263 b.Property<int>("MedicineId") 264 .HasColumnType("integer"); 265 266 b.Property<DateTime>("CreatedOn") 267 .HasColumnType("timestamp without time zone"); 268 269 b.Property<DateTime?>("DeletedOn") 270 .HasColumnType("timestamp without time zone"); 271 272 b.Property<int>("Id") 273 .HasColumnType("integer") 274 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'"); 275 276 b.HasKey("PheadId", "MedicineId"); 284 b.HasKey("Id"); 285 286 b.HasIndex("HeadId"); 277 287 278 288 b.HasIndex("MedicineId"); … … 315 325 .ValueGeneratedOnAdd() 316 326 .HasColumnType("integer") 317 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'")318 327 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 319 328 … … 353 362 }); 354 363 355 modelBuilder.Entity("FarmatikoData.Models. Medicine", b =>356 { 357 b.HasOne("FarmatikoData.Models.PharmacyHead", null)358 .WithMany(" MedicineList")364 modelBuilder.Entity("FarmatikoData.Models.Pharmacy", b => 365 { 366 b.HasOne("FarmatikoData.Models.PharmacyHead", "PharmacyHead") 367 .WithMany("Pharmacies") 359 368 .HasForeignKey("PharmacyHeadId"); 360 369 }); 361 370 362 modelBuilder.Entity("FarmatikoData.Models.Pharmacy", b => 363 { 364 b.HasOne("FarmatikoData.Models.PharmacyHead", "PHead") 365 .WithMany("PharmaciesList") 366 .HasForeignKey("PheadId") 367 .OnDelete(DeleteBehavior.Cascade) 368 .IsRequired(); 371 modelBuilder.Entity("FarmatikoData.Models.PharmacyHead", b => 372 { 373 b.HasOne("FarmatikoData.Models.User", "User") 374 .WithMany() 375 .HasForeignKey("UserId"); 369 376 }); 370 377 371 378 modelBuilder.Entity("FarmatikoData.Models.PharmacyHeadMedicine", b => 372 379 { 380 b.HasOne("FarmatikoData.Models.PharmacyHead", "Head") 381 .WithMany("Medicines") 382 .HasForeignKey("HeadId"); 383 373 384 b.HasOne("FarmatikoData.Models.Medicine", "Medicine") 374 .WithMany("Medicine List")385 .WithMany("Medicines") 375 386 .HasForeignKey("MedicineId") 376 .OnDelete(DeleteBehavior.Cascade)377 .IsRequired();378 379 b.HasOne("FarmatikoData.Models.PharmacyHead", "Head")380 .WithMany("PHMedicineList")381 .HasForeignKey("PheadId")382 387 .OnDelete(DeleteBehavior.Cascade) 383 388 .IsRequired(); -
FarmatikoData/Models/Medicine.cs
r8e74e2f rdb484c9 23 23 public string Packaging { get; set; } 24 24 //[JsonPropertyName("PHMedicineList")] 25 public ICollection<PharmacyHeadMedicine> Medicine List{ get; set; }25 public ICollection<PharmacyHeadMedicine> Medicines { get; set; } 26 26 public Medicine(string Name, string Strength, string Form, string WayOfIssuing, string Manufacturer, float Price, string Packaging) 27 27 { -
FarmatikoData/Models/Pharmacy.cs
r8e74e2f rdb484c9 27 27 } 28 28 public int PheadId { get; set; } 29 public PharmacyHead P Head { get; internalset; }29 public PharmacyHead PharmacyHead { get; set; } 30 30 } 31 31 } -
FarmatikoData/Models/PharmacyHead.cs
r8e74e2f rdb484c9 21 21 [JsonProperty("Passwd")] 22 22 public string Password { get; set; } 23 [JsonProperty("PharmacyList")] 24 public virtual List<Pharmacy> Pharmacies { get; set; } 25 public virtual List<PharmacyHeadMedicine> Medicines { get; set; } 26 27 public User User { get; set; } 23 28 24 [JsonProperty("PharmacyMedicines")]25 public List<Medicine> MedicineList { get; set; }26 [JsonProperty("Pharmacy")]27 public ICollection<Pharmacy> PharmaciesList { get; set; }28 //[JsonProperty("PHMedicineList")]29 public ICollection<PharmacyHeadMedicine> PHMedicineList { get; set; }30 29 31 30 } -
FarmatikoServices/FarmatikoServiceInterfaces/IPHService.cs
r8e74e2f rdb484c9 1 using FarmatikoData.Models; 1 using FarmatikoData.DTOs; 2 using FarmatikoData.Models; 2 3 using System; 3 4 using System.Collections.Generic; … … 11 12 { 12 13 Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo(); 13 Task UpdatePharmacyHead(PharmacyHead pharmacyHead);14 Task UpdatePharmacyHead(PharmacyHeadDto pharmacyHead); 14 15 Task<int> Login(PharmacyHead pharmacyHead); 15 16 Task<bool> ClaimPharmacy(RequestPharmacyHead pharmacy); 16 17 Task<PharmacyHead> GetPharmacyHeadByIdAsync(int id); 17 Task<bool> Add(PharmacyHead pharmacyHead);18 Task<bool> Add(PharmacyHeadDto pharmacyHead); 18 19 Task<bool> Remove(int id); 19 20 Task<bool> RemoveClaimingRequest(int id); 20 objectGetPharmacyHead(string userName);21 PharmacyHeadDto GetPharmacyHead(string userName); 21 22 } 22 23 } -
FarmatikoServices/Services/PHService.cs
r8e74e2f rdb484c9 1 using FarmatikoData.FarmatikoRepoInterfaces; 1 using FarmatikoData.DTOs; 2 using FarmatikoData.FarmatikoRepoInterfaces; 2 3 using FarmatikoData.Models; 3 4 using FarmatikoServices.FarmatikoServiceInterfaces; … … 57 58 58 59 59 public async Task UpdatePharmacyHead(PharmacyHead pharmacyHead)60 public async Task UpdatePharmacyHead(PharmacyHeadDto pharmacyHead) 60 61 { 61 62 if (pharmacyHead != null) … … 63 64 var phead = _iPHRepo.GetPharmacyHead(pharmacyHead.Email); 64 65 65 /*if (pharmacyHead.PharmaciesList.Count() == 0) 66 pharmacyHead.PharmaciesList = null;*/ 67 68 69 phead.PHMedicineList = _repository.GetPHMedicines(phead.Email); 70 71 if (phead.MedicineList != pharmacyHead.MedicineList) 72 { 73 phead.MedicineList = pharmacyHead.MedicineList; 74 List<PharmacyHeadMedicine> list = new List<PharmacyHeadMedicine>(); 75 if (pharmacyHead.MedicineList.Count() == 0) 76 { 77 phead.MedicineList = null; 78 int PHMId = phead.PHMedicineList.Select(x => x.Id).Single(); 79 int phId = phead.PHMedicineList.Select(x => x.PheadId).Single(); 80 int medId = phead.PHMedicineList.Select(x => x.MedicineId).Single(); 66 phead.Medicines = _repository.GetPHMedicines(phead.Email).ToList(); 67 68 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 72 List<PharmacyHeadMedicine> list = new List<PharmacyHeadMedicine>(); 73 74 75 76 if (!pharmacyHead.Medicines.Equals(PHMedicines)) 77 { 78 //phead.Medicines = pharmacyHead.Medicines; 79 if (pharmacyHead.Medicines.Count() == 0) 80 { 81 phead.Medicines = null; 82 int PHMId = phead.Medicines.Select(x => x.Id).Single(); 83 int phId = phead.Medicines.Select(x => x.PheadId).Single(); 84 int medId = phead.Medicines.Select(x => x.MedicineId).Single(); 81 85 _iPHRepo.DeletePHMedicine(PHMId, phId, medId); 82 86 return; 83 87 } 84 List<PharmacyHeadMedicine> PHMList = new List<PharmacyHeadMedicine>();85 if (phead.PHMedicineList == pharmacyHead.PHMedicineList)86 { 87 foreach (var med in phead.MedicineList)88 foreach (var med in pharmacyHead.Medicines) 89 { 90 91 PharmacyHeadMedicine PHMObj = phead.Medicines.Select(x => new PharmacyHeadMedicine 88 92 { 89 //list = phead.PHMedicineList.ToList(); 90 91 var PHMObj = phead.PHMedicineList.Select(x => new PharmacyHeadMedicine 92 { 93 Id = x.Id, 94 PheadId = x.PheadId, 95 Head = x.Head, 96 MedicineId = x.MedicineId, 97 Medicine = x.Medicine 98 }).Where(x => x.MedicineId == med.Id).Single(); 99 if (PHMObj == null || PHMObj == default) 100 break; 101 if (PHMObj.MedicineId == med.Id) 102 list.Add(PHMObj); 103 104 } 105 106 phead.PHMedicineList = list; 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 107 104 } 108 105 106 phead.Medicines = list; 107 109 108 await _iPHRepo.UpdatePharmacyHead(phead); 110 109 } 111 else if (!phead.Equals(pharmacyHead)) 112 { 113 await _iPHRepo.UpdatePharmacyHead(pharmacyHead); 110 PharmacyHead head = new PharmacyHead() 111 { 112 Name = pharmacyHead.Name, 113 Email = pharmacyHead.Email, 114 Password = pharmacyHead.Password, 115 Pharmacies = pharmacyHead.Pharmacies, 116 Medicines = list 117 }; 118 if (!phead.Equals(head)) 119 { 120 await _iPHRepo.UpdatePharmacyHead(head); 114 121 } 115 122 else throw new Exception("Cannot update pharmacy head since there was no changes."); … … 117 124 else throw new Exception("PharmacyHead has a null value."); 118 125 } 119 public async Task<bool> Add(PharmacyHead pharmacyHead)126 public async Task<bool> Add(PharmacyHeadDto pharmacyHead) 120 127 { 121 128 if (pharmacyHead != null) 122 129 { 123 await _iPHRepo.Add(pharmacyHead); 130 PharmacyHead head = new PharmacyHead() 131 { 132 Name = pharmacyHead.Name, 133 Email = pharmacyHead.Email, 134 Password = pharmacyHead.Password, 135 Pharmacies = null, 136 Medicines = null 137 }; 138 await _iPHRepo.Add(head); 124 139 return true; 125 140 } … … 149 164 } 150 165 151 public objectGetPharmacyHead(string userName)166 public PharmacyHeadDto GetPharmacyHead(string userName) 152 167 { 153 168 if (userName != null) … … 156 171 List<PharmacyHeadMedicine> PHMedicines = _iPHRepo.GetPharmacyHeadMedicines(userName); 157 172 List<Medicine> Medicines = _repository.GetMedicines().ToList(); 158 List<Medicine> PHMedicineList = new List<Medicine>(); 159 160 161 //var meds = PHMedicines.Where(x => x.Id == Phead.Id).ToList(); 162 var pharmacies = _iPHRepo.GetPharmacies(); 163 var PheadPharms = pharmacies.Where(x => x.PheadId == Phead.Id).ToList(); 173 List<Medicine> MedicineList = new List<Medicine>(); 174 164 175 var user = _repository.GetRole(userName); 165 176 … … 167 178 if (user.UserRole.ToString().Equals("Admin")) 168 179 { 169 var Admin = new PharmacyHead() 180 List<Pharmacy> pharmacies = new List<Pharmacy>(); 181 pharmacies = Phead.Pharmacies; 182 var Admin = new PharmacyHeadDto() 170 183 { 171 184 Id = user.Id, … … 173 186 Name = user.Name, 174 187 Password = user.Password, 175 Pharmacies List = Phead.PharmaciesList188 Pharmacies = pharmacies 176 189 }; 177 190 178 191 return Admin; 179 192 } 180 181 if (PheadPharms.Count() > 0 || PheadPharms != null) 182 Phead.PharmaciesList = PheadPharms; 183 else Phead.PharmaciesList = pharmacies; 184 185 if (Phead.PHMedicineList.Count() > 0 || Phead.PHMedicineList != null) 193 else 186 194 { 187 195 foreach (var med in Medicines) 188 196 { 189 190 var PHMObj = Phead.PHMedicineList.Where(x => x.MedicineId == med.Id).SingleOrDefault(); 197 var PHMObj = Phead.Medicines.Where(x => x.MedicineId == med.Id).SingleOrDefault(); 191 198 if (PHMObj == null) 192 199 { 193 200 continue; 194 201 } 195 var phm = Phead.MedicineList;196 202 if (PHMObj.MedicineId == med.Id) 197 203 { … … 207 213 Packaging = med.Packaging 208 214 }; 209 PHMedicineList.Add(medicine);215 MedicineList.Add(medicine); 210 216 } 211 217 } 212 Phead.MedicineList = PHMedicineList; 213 } 214 else 215 { 216 Phead.MedicineList = Medicines; 217 } 218 219 PharmacyHead pharHead = new PharmacyHead() 218 } 219 220 PharmacyHeadDto pharmacyHead = new PharmacyHeadDto() 220 221 { 221 222 Id = Phead.Id, 222 Medicine List = Phead.MedicineList,223 Pharmacies List = Phead.PharmaciesList,223 Medicines = MedicineList, 224 Pharmacies = Phead.Pharmacies, 224 225 Email = Phead.Email, 225 226 Name = Phead.Name, 226 227 Password = Phead.Password 227 228 }; 228 return phar Head;229 return pharmacyHead; 229 230 } 230 231 else throw new Exception("Username is null."); -
FarmatikoServices/Services/ProcessJSONService.cs
r8e74e2f rdb484c9 174 174 HealthFacility facility = _service.GetFacilityJSON(Convert.ToString(FacilityName)); 175 175 176 if (facility != null )176 if (facility != null && facility != default) 177 177 { 178 178 HealthFacility Facility = new HealthFacility( -
FarmatikoServices/Services/Service.cs
r8e74e2f rdb484c9 130 130 public User MakeUser(PharmacyHead head) 131 131 { 132 var users = _repository.GetUsers();132 133 133 134 134 User user = new User() -
FarmatikoServices/Services/SystemService.cs
r8e74e2f rdb484c9 7 7 public interface ISystemService 8 8 { 9 9 public void ParseHTML(); 10 10 } 11 11 public class SystemService
Note:
See TracChangeset
for help on using the changeset viewer.