public IActionResult Put(int id, [FromBody] MedicationPostView medicationPostView)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CustomerMed customerMed = new CustomerMed
            {
                CustomerMedId    = medicationPostView.CustomerMedId,
                MedicationId     = medicationPostView.MedicationId,
                CustomerId       = medicationPostView.CustomerId,
                Usage            = medicationPostView.Usage,
                Frequency        = medicationPostView.Frequency,
                Notes            = medicationPostView.Notes,
                ShowOnPublicView = medicationPostView.ShowOnPublicView,
                CustUserName     = medicationPostView.CustUserName
            };

            Medication medication = new Medication
            {
                MedicationId     = medicationPostView.MedicationId,
                GenericName      = medicationPostView.GenericName,
                BrandName        = medicationPostView.BrandName,
                Dosage           = medicationPostView.Dosage,
                SideEffects      = medicationPostView.SideEffects,
                DrugInteractions = medicationPostView.DrugInteractions
            };

            _context.Entry(medication).State  = EntityState.Modified;
            _context.Entry(customerMed).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MedicationExists(medicationPostView.MedicationId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(new StatusCodeResult(StatusCodes.Status204NoContent));
        }
Beispiel #2
0
        public IActionResult Put(int id, [FromBody] Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customer.CustomerId)
            {
                return(BadRequest());
            }

            _context.Entry(customer).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(customer.CustomerId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(new StatusCodeResult(StatusCodes.Status204NoContent));
        }