コード例 #1
0
 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;
         }
         Evento_Idioma evento_idioma = evento_idiomaRepository.GetById(include, (p => p.Id == Id));
         if (evento_idioma == null)
         {
             throw new HttpResponseException(HttpStatusCode.NotFound);
         }
         return(Request.CreateResponse <Evento_Idioma>(HttpStatusCode.OK, evento_idioma, formatter));
     } catch (Exception _excepcion) {
         log.Error(_excepcion);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion));
     }
 }
コード例 #2
0
        public HttpResponseMessage Put(int Id, string cultura, EventoModel evento)
        {
            try {
                if (ModelState.IsValid)
                {
                    if (cultura != Localizacion.CulturaPorDefecto)
                    {
                        Evento      _evento           = eventoRepository.GetById(new string[] {}, (p => p.Id == Id));
                        EventoModel _eventoPorDefecto = new EventoModel();
                        // Solo funciona el Mapper si se ha configurado el Mapper con Mapper.CreateMap<EmpresaModel, EmpresaModel>(); Se está creando en la carpeta mappers.
                        _eventoPorDefecto = AutoMapper.Mapper.Map <EventoModel, EventoModel>(evento, _eventoPorDefecto);

                        _eventoPorDefecto.Ubicacion   = _evento.Ubicacion;
                        _eventoPorDefecto.Nombre      = _evento.Nombre;
                        _eventoPorDefecto.Descripcion = _evento.Descripcion;

                        var command = AutoMapper.Mapper.Map <EventoModel, CreateOrUpdateEventoCommand>(_eventoPorDefecto);
                        var result  = commandBus.Submit(command);
                    }
                    else
                    {
                        var command = AutoMapper.Mapper.Map <EventoModel, CreateOrUpdateEventoCommand>(evento);
                        var result  = commandBus.Submit(command);
                    }
                    Evento_Idioma _eventoIdioma = evento_IdiomaRepository.GetMany(t => t.IdRegistro == evento.Id && t.Cultura == cultura).FirstOrDefault();
                    var           commandIdioma = AutoMapper.Mapper.Map <Evento_IdiomaModel, CreateOrUpdateEvento_IdiomaCommand>(new Evento_IdiomaModel {
                        Id = (_eventoIdioma != null ? _eventoIdioma.Id : (int)0), IdRegistro = evento.Id, Cultura = cultura, Ubicacion = evento.Ubicacion, Nombre = evento.Nombre, Descripcion = evento.Descripcion
                    });
                    var resultIdioma = commandBus.Submit(commandIdioma);
                    return(Request.CreateResponse <EventoModel>(HttpStatusCode.OK, evento));
                }
                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));
            }
        }
コード例 #3
0
        public ICommandResult Execute(CreateOrUpdateEvento_IdiomaCommand command)
        {
            Evento_Idioma _Evento_Idioma = AutoMapper.Mapper.Map <CreateOrUpdateEvento_IdiomaCommand, Evento_Idioma>(command);

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

            AutoMapper.Mapper.Map <Evento_Idioma, CreateOrUpdateEvento_IdiomaCommand>(_Evento_Idioma, command);

            return(new CommandResult(true));
        }
コード例 #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;
                }
                Evento _evento = eventoRepository.GetById(include, (p => p.Id == Id));
                if (cultura != Localizacion.CulturaPorDefecto)
                {
                    Evento_Idioma _eventoIdioma = evento_IdiomaRepository.GetMany(p => p.IdRegistro == Id && p.Cultura == cultura).FirstOrDefault();

                    // Campos multiidioma
                    if (_eventoIdioma != null)
                    {
                        _evento.Ubicacion   = _eventoIdioma.Ubicacion;
                        _evento.Nombre      = _eventoIdioma.Nombre;
                        _evento.Descripcion = _eventoIdioma.Descripcion;
                    }
                }

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