Changeset e0cdea2 for FarmatikoData
- Timestamp:
- 02/08/21 16:39:25 (4 years ago)
- Branches:
- master
- Children:
- 8eb1e21, dae4cde
- Parents:
- 0a694bb
- Location:
- FarmatikoData
- Files:
-
- 9 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.