public HttpResponseMessage ValidateParentId(int establishmentId, EstablishmentApiScalarModel model) { //System.Threading.Thread.Sleep(2000); // test api latency model.Id = establishmentId; var command = new UpdateEstablishment(model.Id, User); Mapper.Map(model, command); var validationResult = _updateValidator.Validate(command); var propertyName = command.PropertyName(y => y.ParentId); Func<ValidationFailure, bool> forText = x => x.PropertyName == propertyName; if (validationResult.Errors.Any(forText)) return Request.CreateResponse(HttpStatusCode.BadRequest, validationResult.Errors.First(forText).ErrorMessage, "text/plain"); return Request.CreateResponse(HttpStatusCode.OK); }
public HttpResponseMessage Put(int id, EstablishmentApiScalarModel model) { //System.Threading.Thread.Sleep(2000); // test api latency var entity = _queryProcessor.Execute(new EstablishmentById(id)); if (entity == null) throw new HttpResponseException(HttpStatusCode.NotFound); model.Id = id; var command = new UpdateEstablishment(id, User); Mapper.Map(model, command); try { _updateHandler.Handle(command); } catch (ValidationException ex) { var badRequest = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message, "text/plain"); return badRequest; } var response = Request.CreateResponse(HttpStatusCode.OK, "Establishment was successfully updated."); return response; }