public HttpResponseMessage Post(CategoriaFoto_IdiomaModel categoriafoto_idioma) { try { if (ModelState.IsValid) { if (categoriafoto_idioma.Id == 0) { var command = AutoMapper.Mapper.Map <CategoriaFoto_IdiomaModel, CreateOrUpdateCategoriaFoto_IdiomaCommand>(categoriafoto_idioma); var result = commandBus.Submit(command); if (result.Success) { categoriafoto_idioma = AutoMapper.Mapper.Map <CreateOrUpdateCategoriaFoto_IdiomaCommand, CategoriaFoto_IdiomaModel>(command); var response = Request.CreateResponse <CategoriaFoto_IdiomaModel>(HttpStatusCode.Created, categoriafoto_idioma); string uri = Url.Route(null, new { Id = categoriafoto_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, CategoriaFoto_IdiomaModel categoriafoto_idioma) { try { if (ModelState.IsValid) { var command = AutoMapper.Mapper.Map <CategoriaFoto_IdiomaModel, CreateOrUpdateCategoriaFoto_IdiomaCommand>(categoriafoto_idioma); var result = commandBus.Submit(command); return(Request.CreateResponse <CategoriaFoto_IdiomaModel>(HttpStatusCode.OK, categoriafoto_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)); } }