Ejemplo n.º 1
0
        private Medicine UpdateMedicine(MedicineContract medContract)
        {
            var medicine = _context.Medicines.Find(medContract.Id);

            medicine.Name            = medContract.Name;
            medicine.CurrentQuantity = medContract.CurrentQuantity;
            _context.Medicines.Update(medicine);
            return(medicine);
        }
Ejemplo n.º 2
0
        private Medicine AddMedicine(MedicineContract medContract)
        {
            var medicine = new Medicine {
                Id              = 0,
                Name            = medContract.Name,
                CurrentQuantity = medContract.CurrentQuantity
            };

            _context.Medicines.Add(medicine);
            return(medicine);
        }
Ejemplo n.º 3
0
 public ActionResult AlterMedicine([FromBody] MedicineContract medicine)
 {
     try{
         Medicine newMedicine;
         if (medicine.Id > 0)
         {
             newMedicine = UpdateMedicine(medicine);
         }
         else
         {
             newMedicine = AddMedicine(medicine);
         }
         _context.SaveChanges();
         return(Ok(newMedicine));
     } catch (Exception ex) {
         return(BadRequest(ex.Message));
     }
 }