Beispiel #1
0
 public HttpResponseMessage Get([FromUri] short 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;
         }
         TipoEvento_Idioma tipoevento_idioma = tipoevento_idiomaRepository.GetById(include, (p => p.Id == Id));
         if (tipoevento_idioma == null)
         {
             throw new HttpResponseException(HttpStatusCode.NotFound);
         }
         return(Request.CreateResponse <TipoEvento_Idioma>(HttpStatusCode.OK, tipoevento_idioma, formatter));
     } catch (Exception _excepcion) {
         log.Error(_excepcion);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion));
     }
 }
Beispiel #2
0
        public ICommandResult Execute(CreateOrUpdateTipoEvento_IdiomaCommand command)
        {
            TipoEvento_Idioma _TipoEvento_Idioma = AutoMapper.Mapper.Map <CreateOrUpdateTipoEvento_IdiomaCommand, TipoEvento_Idioma>(command);

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

            AutoMapper.Mapper.Map <TipoEvento_Idioma, CreateOrUpdateTipoEvento_IdiomaCommand>(_TipoEvento_Idioma, command);

            return(new CommandResult(true));
        }
Beispiel #3
0
        public HttpResponseMessage Put(short Id, string cultura, TipoEventoModel tipoevento)
        {
            try {
                if (ModelState.IsValid)
                {
                    if (cultura != Localizacion.CulturaPorDefecto)
                    {
                        TipoEvento      _tipoevento           = tipoeventoRepository.GetById(new string[] {}, (p => p.Id == Id));
                        TipoEventoModel _tipoeventoPorDefecto = new TipoEventoModel();
                        // Solo funciona el Mapper si se ha configurado el Mapper con Mapper.CreateMap<EmpresaModel, EmpresaModel>(); Se está creando en la carpeta mappers.
                        _tipoeventoPorDefecto = AutoMapper.Mapper.Map <TipoEventoModel, TipoEventoModel>(tipoevento, _tipoeventoPorDefecto);

                        _tipoeventoPorDefecto.Nombre = _tipoevento.Nombre;

                        var command = AutoMapper.Mapper.Map <TipoEventoModel, CreateOrUpdateTipoEventoCommand>(_tipoeventoPorDefecto);
                        var result  = commandBus.Submit(command);
                    }
                    else
                    {
                        var command = AutoMapper.Mapper.Map <TipoEventoModel, CreateOrUpdateTipoEventoCommand>(tipoevento);
                        var result  = commandBus.Submit(command);
                    }
                    TipoEvento_Idioma _tipoeventoIdioma = tipoevento_IdiomaRepository.GetMany(t => t.IdRegistro == tipoevento.Id && t.Cultura == cultura).FirstOrDefault();
                    var commandIdioma = AutoMapper.Mapper.Map <TipoEvento_IdiomaModel, CreateOrUpdateTipoEvento_IdiomaCommand>(new TipoEvento_IdiomaModel {
                        Id = (_tipoeventoIdioma != null ? _tipoeventoIdioma.Id : (short)0), IdRegistro = tipoevento.Id, Cultura = cultura, Nombre = tipoevento.Nombre
                    });
                    var resultIdioma = commandBus.Submit(commandIdioma);
                    return(Request.CreateResponse <TipoEventoModel>(HttpStatusCode.OK, tipoevento));
                }
                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 #4
0
        public HttpResponseMessage Get([FromUri] short 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;
                }
                TipoEvento _tipoevento = tipoeventoRepository.GetById(include, (p => p.Id == Id));
                if (cultura != Localizacion.CulturaPorDefecto)
                {
                    TipoEvento_Idioma _tipoeventoIdioma = tipoevento_IdiomaRepository.GetMany(p => p.IdRegistro == Id && p.Cultura == cultura).FirstOrDefault();

                    // Campos multiidioma
                    if (_tipoeventoIdioma != null)
                    {
                        _tipoevento.Nombre = _tipoeventoIdioma.Nombre;
                    }
                }

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