Changeset 0a694bb
- Timestamp:
- 02/07/21 16:25:56 (4 years ago)
- Branches:
- master
- Children:
- e0cdea2
- Parents:
- ac51326
- Files:
-
- 13 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
Farmatiko/Controllers/AdminController.cs
rac51326 r0a694bb 44 44 [HttpPost] 45 45 [Route("api/pharmacyhead/add")] 46 public async Task<IActionResult> AddPharmacyHead([FromBody]PharmacyHead pharmacyHead)46 public async Task<IActionResult> AddPharmacyHead([FromBody]PharmacyHeadDto pharmacyHead) 47 47 { 48 await _service.AddPharmacyHead(pharmacyHead); 49 return Ok("Pharmacy added."); 48 bool Success = await _service.AddPharmacyHead(pharmacyHead); 49 if (Success) 50 return Ok("Pharmacy added."); 51 return BadRequest(); 50 52 } 51 53 52 [Http Delete]54 [HttpPost] 53 55 [Route("api/pharmacyhead/delete/{Id}")] 54 56 public async Task<IActionResult> RemovePharmacyHead([FromRoute] int Id) … … 57 59 return Ok(); 58 60 } 59 [Http Delete]61 [HttpPost] 60 62 [Route("api/pharmacyhead/requests/{Id}")] 61 63 public IActionResult RejectRequest([FromRoute] int Id) -
Farmatiko/Controllers/PharmacyHeadController.cs
rac51326 r0a694bb 44 44 return Ok(Success); 45 45 } 46 [HttpDelete]46 /* [HttpDelete] 47 47 [Route("api/pharmacyhead/delete/{Id}")] 48 48 public async Task<IActionResult> Remove([FromRoute] int Id) … … 50 50 bool Success = await _PHService.Remove(Id); 51 51 return Ok(Success); 52 } 53 [HttpPost]52 }*/ 53 /* [HttpPost] 54 54 [Route("api/pharmacyhead/requests/{Id}")] 55 55 public async Task<IActionResult> RemoveClaimingRequest([FromRoute] int Id) … … 57 57 bool Success = await _PHService.RemoveClaimingRequest(Id); 58 58 return Ok(Success); 59 } 59 }*/ 60 60 61 61 } -
FarmatikoData/DTOs/PharmacyDTO.cs
rac51326 r0a694bb 11 11 [JsonProperty("name")] 12 12 public string Name { get; set; } 13 [JsonProperty(" Location")]13 [JsonProperty("location")] 14 14 public string Location { get; set; } 15 15 [JsonProperty("address")] 16 16 public string Address { get; set; } 17 [JsonProperty("work alltime")]17 [JsonProperty("workAllTime")] 18 18 public bool WorkAllTime { get; set; } 19 19 [JsonProperty("headName")] -
FarmatikoData/FarmatikoDataContext.cs
rac51326 r0a694bb 38 38 .ToTable("PHRequests"); 39 39 40 modelBuilder.Entity<PharmacyHead>() 41 .Property(p => p.Id) 42 .ValueGeneratedOnAdd(); 43 40 44 /*modelBuilder.Entity<Medicine>() 41 45 .Property(x => x.Id) … … 74 78 .WithMany(p => p.Pharmacy); 75 79 */ 76 80 77 81 base.OnModelCreating(modelBuilder); 78 82 } -
FarmatikoData/FarmatikoRepo/Repository.cs
rac51326 r0a694bb 71 71 Address = x.Address, 72 72 WorkAllTime = x.WorkAllTime, 73 PheadId = x.PheadId 73 PheadId = x.PheadId, 74 PharmacyHead = x.PharmacyHead 74 75 }).Take(5).ToListAsync(); 75 76 return Pharmacies; … … 91 92 { 92 93 var SearchQuery = await _context.HealthFacilities 93 .Where(x => x.Name. IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0)94 .Where(x => x.Name.ToLowerInvariant().Contains(query.ToLowerInvariant())) 94 95 .OrderBy(x => x.Name).ToListAsync(); 95 96 … … 100 101 { 101 102 var SearchQuery = await _context.Medicines 102 .Where(x => x.Name. IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0)103 .Where(x => x.Name.ToLowerInvariant().Contains(query.ToLowerInvariant())) 103 104 .OrderBy(x => x.Name).ToListAsync(); 104 105 … … 109 110 { 110 111 var SearchQuery = await _context.Pharmacies 111 .Where(x => x.Name. IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0)112 .Where(x => x.Name.ToLowerInvariant().Contains(query.ToLowerInvariant())) 112 113 .OrderBy(x => x.Name).ToListAsync(); 113 114 … … 118 119 { 119 120 var SearchQuery = await _context.HealthcareWorkers 120 .Where(x => x.Name. IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0)121 .Where(x => x.Name.ToLowerInvariant().Contains(query.ToLowerInvariant())) 121 122 .OrderBy(x => x.Name).ToListAsync(); 122 123 … … 154 155 if (pharmacyHead.Id == 0) 155 156 { 156 var pheads = await _context.PharmacyHeads.ToListAsync(); 157 if (!pheads.Select(x => x.Equals(pharmacyHead)).FirstOrDefault()) 157 var pheads = await _context.PharmacyHeads.Select(x => new PharmacyHead 158 { 159 Name = x.Name, 160 Email = x.Email 161 }).ToListAsync(); 162 var pheadusr = pheads.Where(x => x.Email.Equals(pharmacyHead.Email)).ToList(); 163 if (pheadusr == null || pheadusr.Count() == 0) 158 164 { 159 165 await _context.PharmacyHeads.AddAsync(pharmacyHead); … … 285 291 } 286 292 287 public async Task AddUser(User user)293 public async Task<bool> AddUser(User user) 288 294 { 289 295 if (user.Id == 0) 290 296 { 291 var users = await _context.Users.ToListAsync(); 292 if (!users.Select(x => x.Equals(user)).FirstOrDefault()) 297 var users = await _context.Users.Select(x => new User 298 { 299 Name = x.Name, 300 Email = x.Email, 301 Password = x.Password, 302 UserRole = x.UserRole 303 }).ToListAsync(); 304 var usr = users.Where(x => x.Email.Equals(user.Email)).ToList(); 305 if (usr != null || usr.Count() > 0) 306 { 307 return true; 308 } 309 else 293 310 { 294 311 await _context.Users.AddAsync(user); 295 312 await _context.SaveChangesAsync(); 313 return true; 296 314 } 297 315 } 316 return false; 298 317 } 299 318 300 319 public async Task<List<PharmacyHeadMedicine>> GetAllPHMedicines() 301 320 { 302 var list = await _context.PharmacyHeadMedicines.ToListAsync(); 321 var list = await _context.PharmacyHeadMedicines.Select(x => new PharmacyHeadMedicine 322 { 323 PheadId = x.PheadId, 324 Head = x.Head, 325 MedicineId = x.MedicineId, 326 Medicine = x.Medicine 327 } 328 ).ToListAsync(); 303 329 return list; 304 330 } -
FarmatikoData/FarmatikoRepoInterfaces/IRepository.cs
rac51326 r0a694bb 46 46 User GetRole(string userName); 47 47 ICollection<PharmacyHeadMedicine> GetPHMedicines(string email); 48 Task AddUser(User user);48 Task<bool> AddUser(User user); 49 49 } 50 50 } -
FarmatikoData/Migrations/20210205174704_Initial-Migration.Designer.cs
rac51326 r0a694bb 11 11 { 12 12 [DbContext(typeof(FarmatikoDataContext))] 13 [Migration("20210 124191844_InitialMigration")]13 [Migration("20210205174704_Initial-Migration")] 14 14 partial class InitialMigration 15 15 { … … 101 101 .ValueGeneratedOnAdd() 102 102 .HasColumnType("integer") 103 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'")104 103 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 105 104 … … 188 187 .ValueGeneratedOnAdd() 189 188 .HasColumnType("integer") 190 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'")191 189 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 192 190 … … 230 228 .ValueGeneratedOnAdd() 231 229 .HasColumnType("integer") 232 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'")233 230 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 234 231 … … 251 248 .HasColumnType("text"); 252 249 253 b.Property<int ?>("UserId")254 .HasColumnType("integer"); 255 256 b.HasKey("Id"); 257 258 b.HasIndex("UserI d");250 b.Property<int>("UserID") 251 .HasColumnType("integer"); 252 253 b.HasKey("Id"); 254 255 b.HasIndex("UserID"); 259 256 260 257 b.ToTable("PharmacyHeads"); … … 266 263 .ValueGeneratedOnAdd() 267 264 .HasColumnType("integer") 268 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'")269 265 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 270 266 … … 298 294 .ValueGeneratedOnAdd() 299 295 .HasColumnType("integer") 300 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'")301 296 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 302 297 … … 375 370 b.HasOne("FarmatikoData.Models.User", "User") 376 371 .WithMany() 377 .HasForeignKey("UserId"); 372 .HasForeignKey("UserID") 373 .OnDelete(DeleteBehavior.Cascade) 374 .IsRequired(); 378 375 }); 379 376 -
FarmatikoData/Migrations/20210205174704_Initial-Migration.cs
rac51326 r0a694bb 15 15 Id = table.Column<int>(nullable: false) 16 16 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), 17 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: 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), … … 125 125 Name = table.Column<string>(nullable: false), 126 126 Password = table.Column<string>(nullable: false), 127 UserI d = table.Column<int>(nullable: true)127 UserID = table.Column<int>(nullable: false) 128 128 }, 129 129 constraints: table => … … 131 131 table.PrimaryKey("PK_PharmacyHeads", x => x.Id); 132 132 table.ForeignKey( 133 name: "FK_PharmacyHeads_Users_UserI d",134 column: x => x.UserI d,133 name: "FK_PharmacyHeads_Users_UserID", 134 column: x => x.UserID, 135 135 principalTable: "Users", 136 136 principalColumn: "Id", 137 onDelete: ReferentialAction. Restrict);137 onDelete: ReferentialAction.Cascade); 138 138 }); 139 139 … … 172 172 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 173 173 DeletedOn = table.Column<DateTime>(nullable: true), 174 PheadId = table.Column<int>(nullable: true),174 PheadId = table.Column<int>(nullable: false), 175 175 HeadId = table.Column<int>(nullable: true), 176 MedicineId = table.Column<int>(nullable: true)176 MedicineId = table.Column<int>(nullable: false) 177 177 }, 178 178 constraints: table => … … 242 242 243 243 migrationBuilder.CreateIndex( 244 name: "IX_PharmacyHeads_UserI d",244 name: "IX_PharmacyHeads_UserID", 245 245 table: "PharmacyHeads", 246 column: "UserI d");246 column: "UserID"); 247 247 248 248 migrationBuilder.CreateIndex( -
FarmatikoData/Migrations/FarmatikoDataContextModelSnapshot.cs
rac51326 r0a694bb 99 99 .ValueGeneratedOnAdd() 100 100 .HasColumnType("integer") 101 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'")102 101 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 103 102 … … 186 185 .ValueGeneratedOnAdd() 187 186 .HasColumnType("integer") 188 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'")189 187 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 190 188 … … 228 226 .ValueGeneratedOnAdd() 229 227 .HasColumnType("integer") 230 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'")231 228 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 232 229 … … 249 246 .HasColumnType("text"); 250 247 251 b.Property<int ?>("UserId")252 .HasColumnType("integer"); 253 254 b.HasKey("Id"); 255 256 b.HasIndex("UserI d");248 b.Property<int>("UserID") 249 .HasColumnType("integer"); 250 251 b.HasKey("Id"); 252 253 b.HasIndex("UserID"); 257 254 258 255 b.ToTable("PharmacyHeads"); … … 264 261 .ValueGeneratedOnAdd() 265 262 .HasColumnType("integer") 266 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'")267 263 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 268 264 … … 296 292 .ValueGeneratedOnAdd() 297 293 .HasColumnType("integer") 298 .HasAnnotation("Npgsql:IdentitySequenceOptions", "'1', '1', '', '', 'False', '1'")299 294 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); 300 295 … … 373 368 b.HasOne("FarmatikoData.Models.User", "User") 374 369 .WithMany() 375 .HasForeignKey("UserId"); 370 .HasForeignKey("UserID") 371 .OnDelete(DeleteBehavior.Cascade) 372 .IsRequired(); 376 373 }); 377 374 -
FarmatikoData/Models/Medicine.cs
rac51326 r0a694bb 23 23 public string Packaging { get; set; } 24 24 //[JsonPropertyName("PHMedicineList")] 25 public ICollection<PharmacyHeadMedicine> Medicines { get; set; }25 public virtual 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
rac51326 r0a694bb 5 5 using FarmatikoData.Base; 6 6 using Microsoft.EntityFrameworkCore; 7 using Newtonsoft.Json; 7 8 8 9 namespace FarmatikoData.Models … … 12 13 public Pharmacy() { } 13 14 [Required] 15 [JsonProperty("name")] 14 16 public string Name { get; set; } 15 17 [Required] 18 [JsonProperty("location")] 16 19 public string Location { get; set; } 17 20 [Required] 21 [JsonProperty("address")] 18 22 public string Address { get; set; } 19 23 [Required] 24 [JsonProperty("workAllTime")] 20 25 public bool WorkAllTime { get; set; } 21 26 public Pharmacy(string Name, string Location, string Address, bool WorkAllTime) -
FarmatikoData/Models/PharmacyHead.cs
rac51326 r0a694bb 24 24 public virtual List<Pharmacy> Pharmacies { get; set; } 25 25 public virtual List<PharmacyHeadMedicine> Medicines { get; set; } 26 26 27 public int UserID { get; set; } 27 28 public User User { get; set; } 28 29 -
FarmatikoServices/FarmatikoServiceInterfaces/IService.cs
rac51326 r0a694bb 28 28 Task AddFacility(HealthFacility healthFacilities); 29 29 Task AddPharmacy(Pharmacy pharmacy); 30 Task AddPharmacyHead(PharmacyHeadpharmacyHead);30 Task<bool> AddPharmacyHead(PharmacyHeadDto pharmacyHead); 31 31 Task AddMedicines(Medicine medicine); 32 32 Task AddPandemic(Pandemic pandemic); -
FarmatikoServices/Services/PHService.cs
rac51326 r0a694bb 73 73 74 74 75 76 if (!pharmacyHead.Medicines.Equals(PHMedicines)) 77 { 78 //phead.Medicines = pharmacyHead.Medicines; 79 if (pharmacyHead.Medicines.Count() == 0) 75 if (pharmacyHead.Medicines != null || pharmacyHead.Medicines.Count() > 0) 76 if (!pharmacyHead.Medicines.Equals(PHMedicines)) 80 77 { 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(); 85 _iPHRepo.DeletePHMedicine(PHMId, phId, medId); 86 return; 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(); 85 _iPHRepo.DeletePHMedicine(PHMId, phId, medId); 86 return; 87 } 88 foreach (var med in pharmacyHead.Medicines) 89 { 90 91 PharmacyHeadMedicine PHMObj = phead.Medicines.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.Medicine.Equals(med)).Single(); 99 if (PHMObj == null || PHMObj == default) 100 break; 101 if (PHMObj.MedicineId == med.Id) 102 list.Add(PHMObj); 103 104 } 105 106 phead.Medicines = list; 107 108 await _iPHRepo.UpdatePharmacyHead(phead); 109 87 110 } 88 foreach (var med in pharmacyHead.Medicines) 89 { 90 91 PharmacyHeadMedicine PHMObj = phead.Medicines.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.Medicine.Equals(med)).Single(); 99 if (PHMObj == null || PHMObj == default) 100 break; 101 if (PHMObj.MedicineId == med.Id) 102 list.Add(PHMObj); 103 104 } 105 106 phead.Medicines = list; 107 108 await _iPHRepo.UpdatePharmacyHead(phead); 111 112 if (pharmacyHead.Pharmacies != null || pharmacyHead.Pharmacies.Count() > 0) 113 { 114 phead.Pharmacies = pharmacyHead.Pharmacies; 109 115 } 110 116 PharmacyHead head = new PharmacyHead() … … 112 118 Name = pharmacyHead.Name, 113 119 Email = pharmacyHead.Email, 114 Password = pharmacyHead.Password, 115 Pharmacies = pharmacyHead.Pharmacies, 116 Medicines = list 120 Password = pharmacyHead.Password 117 121 }; 118 122 if (!phead.Equals(head)) -
FarmatikoServices/Services/Service.cs
rac51326 r0a694bb 48 48 List<MedicineDTO> list = new List<MedicineDTO>(); 49 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>(); 50 List<string> headNames = new List<string>(); 51 List<PharmacyHead> heads = new List<PharmacyHead>(); 52 foreach (var med in Medicines) 53 { 54 var meds = listPHMedicines.Where(x => x.MedicineId == med.Id).ToList(); 55 if (meds != null) 56 { 57 heads = meds.Select(x => x.Head).ToList(); 58 } 54 59 headNames = heads.Select(x => x.Name).ToList(); 55 60 MedicineDTO medicine = new MedicineDTO() … … 89 94 Location = pharm.Location, 90 95 Address = pharm.Address, 91 WorkAllTime = pharm.WorkAllTime, 92 HeadName = pharm.PharmacyHead.Name?? "" 96 WorkAllTime = pharm.WorkAllTime 93 97 }; 98 if (pharm.PharmacyHead != null) 99 { 100 pharmacyDTO.HeadName = pharm.PharmacyHead.Name; 101 } 102 94 103 pharmacies.Add(pharmacyDTO); 95 104 } … … 165 174 166 175 // Ovaa kontrola ja ima samo admin 167 public User MakeUser(PharmacyHead head) 168 { 169 170 176 public async Task<User> MakeUser(PharmacyHead head) 177 { 171 178 User user = new User() 172 179 { … … 176 183 UserRole = User.Role.PharmacyHead 177 184 }; 185 bool Success = await _repository.AddUser(user); 186 if (!Success) 187 return null; 178 188 return user; 179 189 } 180 public async Task AddPharmacyHead(PharmacyHeadpharmacyHead)190 public async Task<bool> AddPharmacyHead(PharmacyHeadDto pharmacyHead) 181 191 { 182 192 if (pharmacyHead != null) 183 193 { 184 var user = MakeUser(pharmacyHead); 185 await _repository.AddUser(user); 186 await _repository.AddPharmacyHead(pharmacyHead); 194 var phead = new PharmacyHead() 195 { 196 Name = pharmacyHead.Name, 197 Email = pharmacyHead.Email, 198 Password = pharmacyHead.Password 199 }; 200 var user = await MakeUser(phead); 201 if (user is null) 202 { 203 return false; 204 } 205 var users = _repository.GetUsers(); 206 var thisUser = users.Where(usr => usr.Value.Email.Equals(user.Email)).Select(x => x.Value).FirstOrDefault(); 207 User user1 = new User() 208 { 209 Name = thisUser.Name, 210 Password = thisUser.Password, 211 Email = thisUser.Email, 212 UserRole = thisUser.UserRole 213 }; 214 phead.User = user1; 215 await _repository.AddPharmacyHead(phead); 216 return true; 187 217 } 188 else throw new Exception("PharmacyHead is null");218 else throw new Exception("PharmacyHeadDto is null"); 189 219 } 190 220 //za json(Sys updater)
Note:
See TracChangeset
for help on using the changeset viewer.