public async Task <IActionResult> UpdatePharmacyMecicines(int id, [FromBody] PharmacyMedicineDto model) { bool isInsideAddUpdate = false; foreach (var item in model.items) { var pharmacyMedicine = await _pharmacyRepository.getPharmacyMedicine(id, item.id); if (pharmacyMedicine == null && item.isSelected == true)// { var modelAddResult = new PharmacyMedicines() { PharmacyId = id, MedicineId = item.id, Quantity = item.Quantity, IsDeleted = false }; _pharmacyRepository.addParmacyMedicine(modelAddResult); isInsideAddUpdate = true; } else if (pharmacyMedicine != null) { pharmacyMedicine.IsDeleted = !item.isSelected; pharmacyMedicine.Quantity = item.Quantity; _pharmacyRepository.updateParmacyMedicine(pharmacyMedicine); isInsideAddUpdate = true; } } if (_pharmacyRepository.SaveChanges() > 0 || isInsideAddUpdate == false) { return(Ok()); } return(BadRequest()); }