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;
         }
         Foto_Idioma foto_idioma = foto_idiomaRepository.GetById(include, (p => p.Id == Id));
         if (foto_idioma == null)
         {
             throw new HttpResponseException(HttpStatusCode.NotFound);
         }
         return(Request.CreateResponse <Foto_Idioma>(HttpStatusCode.OK, foto_idioma, formatter));
     } catch (Exception _excepcion) {
         log.Error(_excepcion);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion));
     }
 }
Beispiel #2
0
        public HttpResponseMessage Put(int Id, string cultura, FotoModel foto)
        {
            try {
                if (ModelState.IsValid)
                {
                    if (cultura != Localizacion.CulturaPorDefecto)
                    {
                        Foto      _foto           = fotoRepository.GetById(new string[] {}, (p => p.Id == Id));
                        FotoModel _fotoPorDefecto = new FotoModel();
                        // Solo funciona el Mapper si se ha configurado el Mapper con Mapper.CreateMap<EmpresaModel, EmpresaModel>(); Se está creando en la carpeta mappers.
                        _fotoPorDefecto = AutoMapper.Mapper.Map <FotoModel, FotoModel>(foto, _fotoPorDefecto);

                        _fotoPorDefecto.Nombre      = _foto.Nombre;
                        _fotoPorDefecto.Descripcion = _foto.Descripcion;

                        var command = AutoMapper.Mapper.Map <FotoModel, CreateOrUpdateFotoCommand>(_fotoPorDefecto);
                        var result  = commandBus.Submit(command);
                    }
                    else
                    {
                        var command = AutoMapper.Mapper.Map <FotoModel, CreateOrUpdateFotoCommand>(foto);
                        var result  = commandBus.Submit(command);
                    }
                    Foto_Idioma _fotoIdioma   = foto_IdiomaRepository.GetMany(t => t.IdRegistro == foto.Id && t.Cultura == cultura).FirstOrDefault();
                    var         commandIdioma = AutoMapper.Mapper.Map <Foto_IdiomaModel, CreateOrUpdateFoto_IdiomaCommand>(new Foto_IdiomaModel {
                        Id = (_fotoIdioma != null ? _fotoIdioma.Id : (int)0), IdRegistro = foto.Id, Cultura = cultura, Nombre = foto.Nombre, Descripcion = foto.Descripcion
                    });
                    var resultIdioma = commandBus.Submit(commandIdioma);
                    return(Request.CreateResponse <FotoModel>(HttpStatusCode.OK, foto));
                }
                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));
            }
        }
Beispiel #3
0
        public ICommandResult Execute(CreateOrUpdateFoto_IdiomaCommand command)
        {
            Foto_Idioma _Foto_Idioma = AutoMapper.Mapper.Map <CreateOrUpdateFoto_IdiomaCommand, Foto_Idioma>(command);

            if (command.Id == 0)
            {
                Foto_IdiomaRepository.Add(_Foto_Idioma);
            }
            else
            {
                Foto_IdiomaRepository.Update(_Foto_Idioma);
            }
            unitOfWork.Commit();

            AutoMapper.Mapper.Map <Foto_Idioma, CreateOrUpdateFoto_IdiomaCommand>(_Foto_Idioma, command);

            return(new CommandResult(true));
        }
Beispiel #4
0
        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;
                }
                Foto _foto = fotoRepository.GetById(include, (p => p.Id == Id));
                if (cultura != Localizacion.CulturaPorDefecto)
                {
                    Foto_Idioma _fotoIdioma = foto_IdiomaRepository.GetMany(p => p.IdRegistro == Id && p.Cultura == cultura).FirstOrDefault();

                    // Campos multiidioma
                    if (_fotoIdioma != null)
                    {
                        _foto.Nombre      = _fotoIdioma.Nombre;
                        _foto.Descripcion = _fotoIdioma.Descripcion;
                    }
                }

                if (_foto == null)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
                return(Request.CreateResponse <Foto>(HttpStatusCode.OK, _foto, formatter));
            } catch (Exception _excepcion) {
                log.Error(_excepcion);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion));
            }
        }