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; } Video_Idioma video_idioma = video_idiomaRepository.GetById(include, (p => p.Id == Id)); if (video_idioma == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(Request.CreateResponse <Video_Idioma>(HttpStatusCode.OK, video_idioma, formatter)); } catch (Exception _excepcion) { log.Error(_excepcion); return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion)); } }
public HttpResponseMessage Put(int Id, string cultura, VideoModel video) { try { if (ModelState.IsValid) { if (cultura != Localizacion.CulturaPorDefecto) { Video _video = videoRepository.GetById(new string[] {}, (p => p.Id == Id)); VideoModel _videoPorDefecto = new VideoModel(); // Solo funciona el Mapper si se ha configurado el Mapper con Mapper.CreateMap<EmpresaModel, EmpresaModel>(); Se está creando en la carpeta mappers. _videoPorDefecto = AutoMapper.Mapper.Map <VideoModel, VideoModel>(video, _videoPorDefecto); _videoPorDefecto.Nombre = _video.Nombre; _videoPorDefecto.Descripcion = _video.Descripcion; _videoPorDefecto.Url = _video.Url; var command = AutoMapper.Mapper.Map <VideoModel, CreateOrUpdateVideoCommand>(_videoPorDefecto); var result = commandBus.Submit(command); } else { var command = AutoMapper.Mapper.Map <VideoModel, CreateOrUpdateVideoCommand>(video); var result = commandBus.Submit(command); } Video_Idioma _videoIdioma = video_IdiomaRepository.GetMany(t => t.IdRegistro == video.Id && t.Cultura == cultura).FirstOrDefault(); var commandIdioma = AutoMapper.Mapper.Map <Video_IdiomaModel, CreateOrUpdateVideo_IdiomaCommand>(new Video_IdiomaModel { Id = (_videoIdioma != null ? _videoIdioma.Id : (int)0), IdRegistro = video.Id, Cultura = cultura, Nombre = video.Nombre, Descripcion = video.Descripcion, Url = video.Url }); var resultIdioma = commandBus.Submit(commandIdioma); return(Request.CreateResponse <VideoModel>(HttpStatusCode.OK, video)); } 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 ICommandResult Execute(CreateOrUpdateVideo_IdiomaCommand command) { Video_Idioma _Video_Idioma = AutoMapper.Mapper.Map <CreateOrUpdateVideo_IdiomaCommand, Video_Idioma>(command); if (command.Id == 0) { Video_IdiomaRepository.Add(_Video_Idioma); } else { Video_IdiomaRepository.Update(_Video_Idioma); } unitOfWork.Commit(); AutoMapper.Mapper.Map <Video_Idioma, CreateOrUpdateVideo_IdiomaCommand>(_Video_Idioma, command); return(new CommandResult(true)); }
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; } Video _video = videoRepository.GetById(include, (p => p.Id == Id)); if (cultura != Localizacion.CulturaPorDefecto) { Video_Idioma _videoIdioma = video_IdiomaRepository.GetMany(p => p.IdRegistro == Id && p.Cultura == cultura).FirstOrDefault(); // Campos multiidioma if (_videoIdioma != null) { _video.Nombre = _videoIdioma.Nombre; _video.Descripcion = _videoIdioma.Descripcion; _video.Url = _videoIdioma.Url; } } if (_video == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(Request.CreateResponse <Video>(HttpStatusCode.OK, _video, formatter)); } catch (Exception _excepcion) { log.Error(_excepcion); return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion)); } }