public MedicationsDto PostMedications(MedicationsDto medicationsDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var medications = Mapper.Map <MedicationsDto, Medications>(medicationsDto); _context.Medications.Add(medications); _context.SaveChanges(); medicationsDto.MedicationsId = medications.MedicationsId; return(medicationsDto); }
public void PutMedications(int id, MedicationsDto medicationsDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var medications = _context.Medications.SingleOrDefault(b => b.MedicationsId == id); if (medications == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Mapper.Map(medicationsDto, medications); _context.SaveChanges(); }