public void Create(CreateRestrictedAccessTimeDto dto) { var restrictedAccessTime = new RestrictedAccessTime { Date = dto.Date, FromTime = dto.FromTime, ToTime = dto.ToTime }; _restrictedAccessTimeRepository.Insert(restrictedAccessTime); }
public IHttpActionResult Create([FromBody] CreateRestrictedAccessTimeDto restrictedAccessTime) { if (restrictedAccessTime == null) { return(BadRequest()); } //custom validations var validator = new CreateRestrictedAccessTimeDtoValidator(); var results = validator.Validate(restrictedAccessTime); if (!results.IsValid) { foreach (var failure in results.Errors) { ModelState.AddModelError(failure.PropertyName, failure.ErrorMessage); } } if (!ModelState.IsValid) { string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState); return(BadRequest(errorMessage)); } try { _restrictedAccessTimeService.Create(restrictedAccessTime); } catch (LogicalException ex) { return(BadRequest(ex.Message)); } catch { return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE)); } return(Ok()); }