public HttpResponseMessage Post(Calendario_IdiomaModel calendario_idioma) { try { if (ModelState.IsValid) { if (calendario_idioma.Id == 0) { var command = AutoMapper.Mapper.Map <Calendario_IdiomaModel, CreateOrUpdateCalendario_IdiomaCommand>(calendario_idioma); var result = commandBus.Submit(command); if (result.Success) { calendario_idioma = AutoMapper.Mapper.Map <CreateOrUpdateCalendario_IdiomaCommand, Calendario_IdiomaModel>(command); var response = Request.CreateResponse <Calendario_IdiomaModel>(HttpStatusCode.Created, calendario_idioma); string uri = Url.Route(null, new { Id = calendario_idioma.Id }); response.Headers.Location = new Uri(Request.RequestUri, uri); return(response); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "No se puede insertar el registro porque ya existe otro con la misma clave. Por favor, revĂsela.")); } } else { var errors = new Dictionary <string, IEnumerable <string> >(); foreach (var keyValue in ModelState) { errors[keyValue.Key] = keyValue.Value.Errors.Select(e => (!string.IsNullOrWhiteSpace(e.ErrorMessage) ? e.ErrorMessage : (e.Exception != null ? e.Exception.Message : string.Empty))); } return(Request.CreateResponse(HttpStatusCode.BadRequest, errors)); } throw new HttpResponseException(HttpStatusCode.BadRequest); } catch (Exception _excepcion) { log.Error(_excepcion); return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion)); } }
public HttpResponseMessage Put(int Id, Calendario_IdiomaModel calendario_idioma) { try { if (ModelState.IsValid) { var command = AutoMapper.Mapper.Map <Calendario_IdiomaModel, CreateOrUpdateCalendario_IdiomaCommand>(calendario_idioma); var result = commandBus.Submit(command); return(Request.CreateResponse <Calendario_IdiomaModel>(HttpStatusCode.OK, calendario_idioma)); } else { var errors = new Dictionary <string, IEnumerable <string> >(); foreach (var keyValue in ModelState) { errors[keyValue.Key] = keyValue.Value.Errors.Select(e => (!string.IsNullOrWhiteSpace(e.ErrorMessage) ? e.ErrorMessage : (e.Exception != null ? e.Exception.Message : string.Empty))); } return(Request.CreateResponse(HttpStatusCode.BadRequest, errors)); } throw new HttpResponseException(HttpStatusCode.BadRequest); } catch (Exception _excepcion) { log.Error(_excepcion); return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion)); } }