示例#1
0
        public IActionResult CreateMedication([FromBody] MedicationCreateDto MedicationDto)
        {
            if (MedicationDto == null)
            {
                return(BadRequest(ModelState));
            }
            var MedicationObj = _mapper.Map <Medication>(MedicationDto);

            if (!_meRepo.CreateMedication(MedicationObj))
            {
                ModelState.AddModelError("", $"Something went wrong when saving the record {MedicationObj.Name}");
                return(StatusCode(500, ModelState));
            }
            return(CreatedAtRoute("GetMedication", new { version = HttpContext.GetRequestedApiVersion().ToString(),
                                                         MedicationId = MedicationObj.Id }, MedicationObj));
        }