public void ValidateCreatePharmacyDTO(CreatePharmacyDTO dto) { ValidateString(dto.Address, "address"); ValidateString(dto.City, "city"); ValidateNumberIsPositive(dto.RegistersCount, "registersCount"); ValidateListNotEmpty(dto.WorkingHours, "workingHours"); }
public async Task <ActionResult> CreatePharmacy([FromBody] CreatePharmacyDTO dto) { List <WorkingHours> workingHours; try { _validator.ValidateCreatePharmacyDTO(dto); workingHours = _workingHoursManager.GetWorkingHoursFromDTO(dto.WorkingHours); } catch (DtoValidationException ex) { return(ApiBadRequest(ex.Message, ex.Parameter)); } Context.Add(new Pharmacy(dto, workingHours)); await Context.SaveChangesAsync(); return(Created()); }