public ICommandResult Execute(CreateOrUpdateTipoColeccionCalendarioCommand command)
        {
            TipoColeccionCalendario _TipoColeccionCalendario = AutoMapper.Mapper.Map <CreateOrUpdateTipoColeccionCalendarioCommand, TipoColeccionCalendario>(command);

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

            AutoMapper.Mapper.Map <TipoColeccionCalendario, CreateOrUpdateTipoColeccionCalendarioCommand>(_TipoColeccionCalendario, command);

            return(new CommandResult(true));
        }
Esempio n. 2
0
        public HttpResponseMessage Put(short Id, string cultura, TipoColeccionCalendarioModel tipocoleccioncalendario)
        {
            try {
                if (ModelState.IsValid)
                {
                    if (cultura != Localizacion.CulturaPorDefecto)
                    {
                        TipoColeccionCalendario      _tipocoleccioncalendario           = tipocoleccioncalendarioRepository.GetById(new string[] {}, (p => p.Id == Id));
                        TipoColeccionCalendarioModel _tipocoleccioncalendarioPorDefecto = new TipoColeccionCalendarioModel();
                        // Solo funciona el Mapper si se ha configurado el Mapper con Mapper.CreateMap<EmpresaModel, EmpresaModel>(); Se está creando en la carpeta mappers.
                        _tipocoleccioncalendarioPorDefecto = AutoMapper.Mapper.Map <TipoColeccionCalendarioModel, TipoColeccionCalendarioModel>(tipocoleccioncalendario, _tipocoleccioncalendarioPorDefecto);

                        _tipocoleccioncalendarioPorDefecto.Nombre = _tipocoleccioncalendario.Nombre;

                        var command = AutoMapper.Mapper.Map <TipoColeccionCalendarioModel, CreateOrUpdateTipoColeccionCalendarioCommand>(_tipocoleccioncalendarioPorDefecto);
                        var result  = commandBus.Submit(command);
                    }
                    else
                    {
                        var command = AutoMapper.Mapper.Map <TipoColeccionCalendarioModel, CreateOrUpdateTipoColeccionCalendarioCommand>(tipocoleccioncalendario);
                        var result  = commandBus.Submit(command);
                    }
                    TipoColeccionCalendario_Idioma _tipocoleccioncalendarioIdioma = tipocoleccioncalendario_IdiomaRepository.GetMany(t => t.IdRegistro == tipocoleccioncalendario.Id && t.Cultura == cultura).FirstOrDefault();
                    var commandIdioma = AutoMapper.Mapper.Map <TipoColeccionCalendario_IdiomaModel, CreateOrUpdateTipoColeccionCalendario_IdiomaCommand>(new TipoColeccionCalendario_IdiomaModel {
                        Id = (_tipocoleccioncalendarioIdioma != null ? _tipocoleccioncalendarioIdioma.Id : (short)0), IdRegistro = tipocoleccioncalendario.Id, Cultura = cultura, Nombre = tipocoleccioncalendario.Nombre
                    });
                    var resultIdioma = commandBus.Submit(commandIdioma);
                    return(Request.CreateResponse <TipoColeccionCalendarioModel>(HttpStatusCode.OK, tipocoleccioncalendario));
                }
                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));
            }
        }
Esempio n. 3
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;
                }
                TipoColeccionCalendario _tipocoleccioncalendario = tipocoleccioncalendarioRepository.GetById(include, (p => p.Id == Id));
                if (cultura != Localizacion.CulturaPorDefecto)
                {
                    TipoColeccionCalendario_Idioma _tipocoleccioncalendarioIdioma = tipocoleccioncalendario_IdiomaRepository.GetMany(p => p.IdRegistro == Id && p.Cultura == cultura).FirstOrDefault();

                    // Campos multiidioma
                    if (_tipocoleccioncalendarioIdioma != null)
                    {
                        _tipocoleccioncalendario.Nombre = _tipocoleccioncalendarioIdioma.Nombre;
                    }
                }

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