public HttpResponseMessage Get([FromUri] int Id, [FromUri] string[] include, [FromUri] bool indent = false) { try { var formatter = new MaxDepthJsonMediaTypeFormatter() { Indent = indent }; if (include.Length > 0) { formatter.SerializerSettings.MaxDepth = 100; //include.Max<string>(s => s.Split('.').Length * 5); formatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects; } else { formatter.SerializerSettings.MaxDepth = 1; } CategoriaFoto_Idioma categoriafoto_idioma = categoriafoto_idiomaRepository.GetById(include, (p => p.Id == Id)); if (categoriafoto_idioma == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(Request.CreateResponse <CategoriaFoto_Idioma>(HttpStatusCode.OK, categoriafoto_idioma, formatter)); } catch (Exception _excepcion) { log.Error(_excepcion); return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion)); } }
public ICommandResult Execute(CreateOrUpdateCategoriaFoto_IdiomaCommand command) { CategoriaFoto_Idioma _CategoriaFoto_Idioma = AutoMapper.Mapper.Map <CreateOrUpdateCategoriaFoto_IdiomaCommand, CategoriaFoto_Idioma>(command); if (command.Id == 0) { CategoriaFoto_IdiomaRepository.Add(_CategoriaFoto_Idioma); } else { CategoriaFoto_IdiomaRepository.Update(_CategoriaFoto_Idioma); } unitOfWork.Commit(); AutoMapper.Mapper.Map <CategoriaFoto_Idioma, CreateOrUpdateCategoriaFoto_IdiomaCommand>(_CategoriaFoto_Idioma, command); return(new CommandResult(true)); }
public HttpResponseMessage Put(int Id, string cultura, CategoriaFotoModel categoriafoto) { try { if (ModelState.IsValid) { if (cultura != Localizacion.CulturaPorDefecto) { CategoriaFoto _categoriafoto = categoriafotoRepository.GetById(new string[] {}, (p => p.Id == Id)); CategoriaFotoModel _categoriafotoPorDefecto = new CategoriaFotoModel(); // Solo funciona el Mapper si se ha configurado el Mapper con Mapper.CreateMap<EmpresaModel, EmpresaModel>(); Se está creando en la carpeta mappers. _categoriafotoPorDefecto = AutoMapper.Mapper.Map <CategoriaFotoModel, CategoriaFotoModel>(categoriafoto, _categoriafotoPorDefecto); _categoriafotoPorDefecto.Nombre = _categoriafoto.Nombre; var command = AutoMapper.Mapper.Map <CategoriaFotoModel, CreateOrUpdateCategoriaFotoCommand>(_categoriafotoPorDefecto); var result = commandBus.Submit(command); } else { var command = AutoMapper.Mapper.Map <CategoriaFotoModel, CreateOrUpdateCategoriaFotoCommand>(categoriafoto); var result = commandBus.Submit(command); } CategoriaFoto_Idioma _categoriafotoIdioma = categoriafoto_IdiomaRepository.GetMany(t => t.IdRegistro == categoriafoto.Id && t.Cultura == cultura).FirstOrDefault(); var commandIdioma = AutoMapper.Mapper.Map <CategoriaFoto_IdiomaModel, CreateOrUpdateCategoriaFoto_IdiomaCommand>(new CategoriaFoto_IdiomaModel { Id = (_categoriafotoIdioma != null ? _categoriafotoIdioma.Id : (int)0), IdRegistro = categoriafoto.Id, Cultura = cultura, Nombre = categoriafoto.Nombre }); var resultIdioma = commandBus.Submit(commandIdioma); return(Request.CreateResponse <CategoriaFotoModel>(HttpStatusCode.OK, categoriafoto)); } 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 Get([FromUri] int Id, [FromUri] string cultura, [FromUri] string[] include, [FromUri] bool indent = false) { try { var formatter = new MaxDepthJsonMediaTypeFormatter() { Indent = indent }; if (include.Length > 0) { formatter.SerializerSettings.MaxDepth = 100; //include.Max<string>(s => s.Split('.').Length * 5); formatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects; } else { formatter.SerializerSettings.MaxDepth = 1; } CategoriaFoto _categoriafoto = categoriafotoRepository.GetById(include, (p => p.Id == Id)); if (cultura != Localizacion.CulturaPorDefecto) { CategoriaFoto_Idioma _categoriafotoIdioma = categoriafoto_IdiomaRepository.GetMany(p => p.IdRegistro == Id && p.Cultura == cultura).FirstOrDefault(); // Campos multiidioma if (_categoriafotoIdioma != null) { _categoriafoto.Nombre = _categoriafotoIdioma.Nombre; } } if (_categoriafoto == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(Request.CreateResponse <CategoriaFoto>(HttpStatusCode.OK, _categoriafoto, formatter)); } catch (Exception _excepcion) { log.Error(_excepcion); return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion)); } }