コード例 #1
0
        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());
        }
コード例 #2
0
 public void updateParmacyMedicine(PharmacyMedicines model)
 {
     _context.PharmacyMedicines.Update(model);
 }
コード例 #3
0
 public void addParmacyMedicine(PharmacyMedicines model)
 {
     _context.PharmacyMedicines.Add(model);
 }