예제 #1
0
 public void ValidateCreatePharmacyDTO(CreatePharmacyDTO dto)
 {
     ValidateString(dto.Address, "address");
     ValidateString(dto.City, "city");
     ValidateNumberIsPositive(dto.RegistersCount, "registersCount");
     ValidateListNotEmpty(dto.WorkingHours, "workingHours");
 }
예제 #2
0
        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());
        }