public async Task <ActionResult> EditPharmacy(int id, [FromBody] EditPharmacyDTO dto) { try { _validator.ValidateEditPharmacyDTO(dto); var pharmacy = await Context.Pharmacies .Include(p => p.PharmacyWorkingHours) .FirstOrDefaultAsync(p => p.Id == id); if (pharmacy == null) { return(ApiNotFound(ApiErrorSlug.ResourceNotFound, ModelName)); } var workingHours = _workingHoursManager.GetWorkingHoursFromDTO(dto.WorkingHours); pharmacy.UpdateFromDTO(dto, workingHours); await Context.SaveChangesAsync(); } catch (DtoValidationException ex) { return(ApiBadRequest(ex.Message, ex.Parameter)); } return(Ok()); }
public void ValidateEditPharmacyDTO(EditPharmacyDTO dto) { if (dto.Address != null) { ValidateString(dto.Address, "address"); } if (dto.City != null) { ValidateString(dto.City, "city"); } if (dto.WorkingHours != null) { ValidateListNotEmpty(dto.WorkingHours, "workingHours"); } }