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; } TipoColeccionCalendario_Idioma tipocoleccioncalendario_idioma = tipocoleccioncalendario_idiomaRepository.GetById(include, (p => p.Id == Id)); if (tipocoleccioncalendario_idioma == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(Request.CreateResponse <TipoColeccionCalendario_Idioma>(HttpStatusCode.OK, tipocoleccioncalendario_idioma, formatter)); } catch (Exception _excepcion) { log.Error(_excepcion); return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion)); } }
public ICommandResult Execute(CreateOrUpdateTipoColeccionCalendario_IdiomaCommand command) { TipoColeccionCalendario_Idioma _TipoColeccionCalendario_Idioma = AutoMapper.Mapper.Map <CreateOrUpdateTipoColeccionCalendario_IdiomaCommand, TipoColeccionCalendario_Idioma>(command); if (command.Id == 0) { TipoColeccionCalendario_IdiomaRepository.Add(_TipoColeccionCalendario_Idioma); } else { TipoColeccionCalendario_IdiomaRepository.Update(_TipoColeccionCalendario_Idioma); } unitOfWork.Commit(); AutoMapper.Mapper.Map <TipoColeccionCalendario_Idioma, CreateOrUpdateTipoColeccionCalendario_IdiomaCommand>(_TipoColeccionCalendario_Idioma, command); return(new CommandResult(true)); }
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)); } }
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)); } }