Beispiel #1
0
        public async Task Update(MapasRuta model)
        {
            try
            {
                var _model = await _db.DbSetMapasRutas.FirstOrDefaultAsync(e => e.MapaId == model.MapaId);

                if (_model != null)
                {
                    //Cuando se elimina el adjunto en modo edicion
                    if (model.AdjuntoId != null)
                    {
                        int id = Convert.ToInt32(model.AdjuntoId);
                        model.AdjuntoId = null;
                        _db.Entry(_model).CurrentValues.SetValues(model);
                        await _db.SaveChangesAsync();

                        await _adjuntoRepo.Delete(id);
                    }
                    //Cuando se agrega un nuevo archivo
                    if (model.Adjunto != null && model.AdjuntoId == null)
                    {
                        Adjunto key = await _adjuntoRepo.CreateAd(model.Adjunto);

                        model.AdjuntoId         = key.AdjuntoId;
                        model.Adjunto.AdjuntoId = key.AdjuntoId;
                    }
                    if (model.claveAutores != null)
                    {
                        var autoresRegistro = await _db.DbSetAutores.Where(e => e.idOC == 1 && e.ContenidoId == model.MapaId).AsNoTracking().ToListAsync();

                        //Eliminacion de autores
                        AutoresCPRepository autoresRepo = new AutoresCPRepository();
                        foreach (var c in autoresRegistro)
                        {
                            await autoresRepo.Delete(c.AutorId);
                        }

                        Autores autor = new Autores();
                        foreach (var clave in model.claveAutores)
                        {
                            autor.clave         = clave;
                            autor.ContenidoId   = model.MapaId;
                            autor.idOC          = 1;
                            autor.FechaRegistro = DateTime.Now;
                            _db.DbSetAutores.Add(autor);
                            await _db.SaveChangesAsync();
                        }
                    }

                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();

                    await cambiaEstadoPublicacion(_model);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
        public async Task <IHttpActionResult> Update(BecarioDirigido Obj)
        {
            try
            {
                log.Info(new MDCSet(this.ControllerContext.RouteData));
                if (Obj.Adjunto != null)
                {
                    //Elimar archivo
                    if (Obj.Adjunto.nombre == "eliminar")
                    {
                        int id = Convert.ToInt32(Obj.AdjuntoId);
                        Obj.AdjuntoId = null;
                        await _repository.Update(Obj);

                        await _adjuntoRepo.Delete(id);

                        return(Ok());
                    }
                    ///Agregar archivo al editar
                    if (Obj.Adjunto.AdjuntoId == 0)
                    {
                        Adjunto key = await _adjuntoRepo.CreateAd(Obj.Adjunto);

                        Obj.AdjuntoId         = key.AdjuntoId;
                        Obj.Adjunto.AdjuntoId = key.AdjuntoId;
                        await _repository.Update(Obj);

                        return(Ok(key));
                    }
                }
                //solución de ALAN replicada
                if (Obj.Adjunto != null)
                {
                    Obj.AdjuntoId = Obj.Adjunto.AdjuntoId;
                }
                await _repository.Update(Obj);

                ////Agregar a OC
                if (Obj.EstadoFlujoId == 3)
                {
                    await new NuevoOCRepository().Create(
                        new NuevoOC("CH",
                                    "BecarioDirigido",
                                    Obj.NombreEstancia,
                                    "IndexCH.html#/detallesbecariodirigido/" + Obj.BecarioDirigidoId + "/",
                                    Obj.BecarioDirigidoId + ""
                                    ));
                }
                return(Ok(Obj));
            }
            catch (Exception e)
            {
                log.Error(new MDCSet(this.ControllerContext.RouteData), e);

                return(InternalServerError(e));
            }
        }
Beispiel #3
0
        public async Task Update(Avance model)
        {
            try
            {
                var _model = await _db.DbSetAvance.FirstOrDefaultAsync(e => e.AvanceId == model.AvanceId);

                if (_model != null)
                {
                    if (model.AdjuntoId != null)
                    {
                        int id = Convert.ToInt32(model.AdjuntoId);
                        model.AdjuntoId = null;
                        _db.Entry(_model).CurrentValues.SetValues(model);
                        await _db.SaveChangesAsync();

                        await _adjuntoRepo.Delete(id);
                    }
                    if (model.Adjunto != null && model.AdjuntoId == null)
                    {
                        Adjunto key = await _adjuntoRepo.CreateAd(model.Adjunto);

                        model.AdjuntoId         = key.AdjuntoId;
                        model.Adjunto.AdjuntoId = key.AdjuntoId;
                    }
                    if (model.avances != null)
                    {
                        //Se eliminan los anteriores para crear un nuevo registro de los agregados
                        var Autores = await _db.DbSetAvanceMiembros.Where(e => e.AvanceId == model.AvanceId).
                                      Select(x => x.AvanceMiembroId).ToListAsync();

                        AvanceMiembrosRepository av = new AvanceMiembrosRepository();
                        foreach (var aut in Autores)
                        {
                            await av.Delete(aut);
                        }

                        //Ahora se crean los nuevos autores
                        foreach (var c in model.avances)
                        {
                            c.AvanceId      = model.AvanceId;
                            c.FechaRegistro = DateTime.Now;;
                            await av.Create(c);
                        }
                    }

                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Actualiza un registro de la tabla asociaciones
        /// </summary>
        /// <param name="asociaciones">objeto de tipo asociaciones que contiene los datos para actualizar </param>
        /// <returns></returns>
        public async Task Update(Asociaciones asociaciones)
        {
            try
            {
                var _asociaciones = await _ctx.Asociaciones.FirstOrDefaultAsync(e => e.AsociacionesId == asociaciones.AsociacionesId);

                if (_asociaciones != null)
                {
                    if (asociaciones.Adjunto != null)
                    {
                        AdjuntoRepository _adjuntoRepo = new AdjuntoRepository();
                        //Eliminar archivo
                        if (asociaciones.Adjunto.nombre == "eliminar")
                        {
                            var id = asociaciones.Adjunto.AdjuntoId;
                            _asociaciones.AdjuntoId = null;
                            asociaciones.AdjuntoId  = null;
                            await _ctx.SaveChangesAsync();

                            await _adjuntoRepo.Delete(id);

                            //formacionacademica.Adjunto = null;
                            //await _faRepo.Update(formacionacademica);
                        }
                        ///Agregar archivo al editar
                        if (asociaciones.Adjunto.AdjuntoId == 0)
                        {
                            if (_asociaciones.AdjuntoId != null)
                            {
                                var id = _asociaciones.AdjuntoId;
                                _asociaciones.AdjuntoId = null;
                                await _ctx.SaveChangesAsync();

                                await _adjuntoRepo.Delete(id);
                            }
                            Adjunto key = await _adjuntoRepo.CreateAd(asociaciones.Adjunto);

                            asociaciones.AdjuntoId = key.AdjuntoId;
                        }
                    }
                    _ctx.Entry(_asociaciones).CurrentValues.SetValues(asociaciones);
                    await _ctx.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
        public async Task <Comunidad> Update(Comunidad model)
        {
            try
            {
                var _model = await _db.DbSetComunidades.FirstOrDefaultAsync(e => e.ComunidadId == model.ComunidadId);

                if (_model != null)
                {
                    //Cuando se elimina el adjunto en modo edicion
                    if (model.idAjunto != null)
                    {
                        int id = Convert.ToInt32(model.idAjunto);
                        model.idAjunto = null;
                        _db.Entry(_model).CurrentValues.SetValues(model);
                        await _db.SaveChangesAsync();

                        await _adjuntoRepo.Delete(id);
                    }
                    if (model.Adjunto != null && model.idAjunto == null)
                    {
                        Adjunto key = await _adjuntoRepo.CreateAd(model.Adjunto);

                        model.idAjunto          = key.AdjuntoId;
                        model.Adjunto.AdjuntoId = key.AdjuntoId;
                        String file    = string.Empty;
                        var    archivo = model.Adjunto.RutaCompleta;
                        try
                        {
                            Byte[] bytes = File.ReadAllBytes(archivo);
                            file            = Convert.ToBase64String(bytes);
                            model.Adjunto64 = file;
                        }
                        catch (Exception e)
                        {
                            model.Adjunto64 = null;
                        }
                    }
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
                return(model);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
        public async Task Update(Propuesta model)
        {
            try
            {
                var _model = await dbGI.DbSetPropuesta.FirstOrDefaultAsync(e => e.Id == model.Id);

                if (_model.AdjuntoId != null)
                {
                    var id = _model.AdjuntoId;
                    _model.AdjuntoId = null;
                    await dbGI.SaveChangesAsync();

                    await new AdjuntoRepository().Delete(id);
                }

                if (model.Adjunto != null)
                {
                    Adjunto key = await _adjuntoRepo.CreateAd(model.Adjunto);

                    model.AdjuntoId         = key.AdjuntoId;
                    model.Adjunto.AdjuntoId = key.AdjuntoId;
                }
                else
                {
                    model.AdjuntoId = null;
                }


                if (_model != null)
                {
                    if (model.EstadoFlujoId == 14)
                    {
                        model.FechaRegistro = DateTime.Now;
                    }
                    ;
                    dbGI.Entry(_model).CurrentValues.SetValues(model);
                    await dbGI.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Beispiel #7
0
        public async Task Update(Lineamientos model)
        {
            try
            {
                var _model = await _db.DbSetLineamientos.FirstOrDefaultAsync(e => e.LineamientoId == model.LineamientoId);

                if (_model != null)
                {
                    if (model.Adjunto != null)
                    {
                        if (_model.AdjuntoId != null)
                        {
                            var id = _model.AdjuntoId;
                            _model.AdjuntoId = null;
                            await _db.SaveChangesAsync();

                            await _adjuntoRepo.Delete(id);
                        }

                        Adjunto key = await _adjuntoRepo.CreateAd(model.Adjunto);

                        model.AdjuntoId = key.AdjuntoId;
                    }
                    else
                    {
                        model.AdjuntoId = null;
                    }
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Beispiel #8
0
        public async Task Update(Post model)
        {
            try
            {
                var _model = await _db.DbSetPost.FirstOrDefaultAsync(e => e.PostId == model.PostId);

                if (_model != null)
                {
                    if (model.Adjunto != null && model.Adjunto.AdjuntoId == 0)
                    {
                        Adjunto key = await _adjuntoRepo.CreateAd(model.Adjunto);

                        model.adjuntoId         = key.AdjuntoId;
                        model.Adjunto.AdjuntoId = key.AdjuntoId;
                    }
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Beispiel #9
0
                                                         public async Task Update(TesisDirigida TD)// UpdateSolicitud
                                                         {
                                                             try
                                                             {
                                                                 if (TD.EstadoFlujoId == 1 && TD.BecarioDirigidoId != null)
                                                                 {
                                                                     var becario = await _ctx.BecarioDirigido.FirstOrDefaultAsync(e => e.BecarioDirigidoId == TD.BecarioDirigidoId);

                                                                     if (becario != null)
                                                                     {
                                                                         becario.EstadoFlujoId = 2;
                                                                         await _ctx.SaveChangesAsync();
                                                                     }
                                                                 }
                                                                 if (TD.EstadoFlujoId == 3 && TD.BecarioDirigidoId != null)
                                                                 {
                                                                     var becario = await _ctx.BecarioDirigido.FirstOrDefaultAsync(e => e.BecarioDirigidoId == TD.BecarioDirigidoId);

                                                                     if (becario != null)
                                                                     {
                                                                         becario.EstadoFlujoId   = 3;
                                                                         becario.AdjuntoId       = TD.AdjuntoId;
                                                                         becario.NombreBecario   = TD.Autor;
                                                                         becario.TesisDirigidaId = TD.TesisDirigidaId;
                                                                         becario.ClavePersona    = TD.ClavePersona;
                                                                         becario.FechaInicio     = TD.FechaInicio;
                                                                         becario.FechaTermino    = TD.FechaTermino;
                                                                         //becario.FechaTermino = TD.FechaTermino;
                                                                         becario.TipoBecaId      = TD.GradoAcademicoId;
                                                                         becario.NombreEstancia  = TD.Titulo;
                                                                         becario.FechaValidacion = TD.FechaValidacion;
                                                                         await _ctx.SaveChangesAsync();
                                                                     }
                                                                 }

                                                                 ////Agregar a OC
                                                                 if (TD.EstadoFlujoId == 3)
                                                                 {
                                                                     await new NuevoOCRepository().Create(
                                                                         new NuevoOC("CH",
                                                                                     "TesisDirigida",
                                                                                     TD.Titulo,
                                                                                     "IndexCH.html#/detallestesisdirigida/" + TD.TesisDirigidaId + "/",
                                                                                     TD.TesisDirigidaId + ""
                                                                                     ));
                                                                 }
                                                                 /////////////////

                                                                 var result = await _ctx.TesisDirigida.FirstOrDefaultAsync(e => e.TesisDirigidaId == TD.TesisDirigidaId);

                                                                 if (TD.EstadoFlujoId == 1 && result.EstadoFlujoId == 3)
                                                                 {
                                                                     await new NuevoOCRepository().DeleteId("TesisDirigida", TD.TesisDirigidaId + "");
                                                                 }
                                                                 if (result != null)
                                                                 {
                                                                     if (TD.Adjunto != null)
                                                                     {
                                                                         //Eliminar archivo
                                                                         AdjuntoRepository adjuntoRepo = new AdjuntoRepository();
                                                                         if (TD.Adjunto.nombre == "eliminar")
                                                                         {
                                                                             int id = Convert.ToInt32(TD.Adjunto.AdjuntoId);
                                                                             result.AdjuntoId = null;
                                                                             await _ctx.SaveChangesAsync();

                                                                             await adjuntoRepo.Delete(id);
                                                                         }
                                                                         ///Agregar archivo al editar
                                                                         if (TD.Adjunto.AdjuntoId == 0)
                                                                         {
                                                                             if (result.AdjuntoId != null)
                                                                             {
                                                                                 var id = result.AdjuntoId;
                                                                                 result.AdjuntoId = null;
                                                                                 await _ctx.SaveChangesAsync();

                                                                                 await adjuntoRepo.Delete(id);
                                                                             }
                                                                             Adjunto key = await adjuntoRepo.CreateAd(TD.Adjunto);

                                                                             TD.AdjuntoId         = key.AdjuntoId;
                                                                             TD.Adjunto.AdjuntoId = key.AdjuntoId;
                                                                         }
                                                                     }
                                                                     _ctx.Entry(result).CurrentValues.SetValues(TD);

                                                                     await _ctx.SaveChangesAsync();
                                                                 }

                                                                 PersonasRepository prep = new PersonasRepository();
                                                                 Personas           p    = await prep.GetByClave(TD.ClavePersona);

                                                                 p.ultimaActualizacion = DateTime.Now;
                                                                 await prep.Update(p);
                                                             }
                                                             catch (Exception e)
                                                             {
                                                                 throw new Exception(e.Message, e);
                                                             }
                                                         }
        public async Task Update(IdeaInnovadora model, List <AutoresIdea> listaAutores)
        {
            //throw new Exception("foo");
            try
            {
                var _model = await dbGI.DbSetIdeaInnovadora.FirstOrDefaultAsync(e => e.IdeaInnovadoraId == model.IdeaInnovadoraId);

                if (_model.AdjuntoId != null)
                {
                    var id = _model.AdjuntoId;
                    _model.AdjuntoId = null;
                    await dbGI.SaveChangesAsync();

                    await new AdjuntoRepository().Delete(id);
                }
                if (model.Adjunto != null)
                {
                    Adjunto key = await _adjuntoRepo.CreateAd(model.Adjunto);

                    model.AdjuntoId         = key.AdjuntoId;
                    model.Adjunto.AdjuntoId = key.AdjuntoId;
                }
                else
                {
                    model.AdjuntoId = null;
                }

                if (model.EstadoFlujoId == 14)
                {
                    model.FechaRegistro = DateTime.Now;
                }
                ;


                if (_model != null)
                {
                    dbGI.Entry(_model).CurrentValues.SetValues(model);
                    await dbGI.SaveChangesAsync();
                }
                try
                {
                    if (listaAutores.Count > 0)
                    {
                        foreach (var autor in listaAutores)
                        {
                            if (autor.Persona.Equals("eliminar"))
                            {
                                var _proponenteExist = await dbGI.DbSetAutoresIdea.FirstOrDefaultAsync(e => e.Id == autor.Id);

                                if (_proponenteExist != null)
                                {
                                    dbGI.DbSetAutoresIdea.Remove(_proponenteExist); await dbGI.SaveChangesAsync();
                                }
                            }
                            if (autor.IdeaInnovadoraId == 0)
                            {
                                autor.ContribucionProponente = null;
                                autor.IdeaInnovadoraId       = model.IdeaInnovadoraId;
                                var result = dbGI.DbSetAutoresIdea.Add(autor);
                                await dbGI.SaveChangesAsync();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message, e);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
                                                                      public async Task <IHttpActionResult> Update(ManualCompetenciaTecnica Obj)
                                                                      {
                                                                          try { log.Info(new MDCSet(this.ControllerContext.RouteData));
                                                                                if (Obj.Adjunto != null)
                                                                                {
                                                                                    //Elimar archivo
                                                                                    if (Obj.Adjunto.nombre == "eliminar")
                                                                                    {
                                                                                        int id = Convert.ToInt32(Obj.AdjuntoId);
                                                                                        Obj.AdjuntoId = null;
                                                                                        await _repository.Update(Obj);

                                                                                        await _adjuntoRepo.Delete(id);

                                                                                        return(Ok());
                                                                                    }
                                                                                    ///Agregar archivo al editar
                                                                                    if (Obj.Adjunto.AdjuntoId == 0)
                                                                                    {
                                                                                        Adjunto key = await _adjuntoRepo.CreateAd(Obj.Adjunto);

                                                                                        Obj.AdjuntoId         = key.AdjuntoId;
                                                                                        Obj.Adjunto.AdjuntoId = key.AdjuntoId;
                                                                                        await _repository.Update(Obj);

                                                                                        return(Ok(key));
                                                                                    }
                                                                                }
                                                                                //solución de ALAN replicada
                                                                                if (Obj.Adjunto != null)
                                                                                {
                                                                                    Obj.AdjuntoId = Obj.Adjunto.AdjuntoId;
                                                                                }
                                                                                await _repository.Update(Obj);

                                                                                return(Ok(Obj)); }
                                                                          catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e);

                                                                                                return(InternalServerError(e)); }
                                                                      }
Beispiel #12
0
                                                                      public async Task Update(CapacitacionYcertificacion Obj)// UpdateSolicitud
                                                                      {
                                                                          try
                                                                          {
                                                                              var result = await _ctx.dbSetCapacitacionYcertificacion.FirstOrDefaultAsync(e => e.CapacitacionYcertificacionId == Obj.CapacitacionYcertificacionId);

                                                                              if (result != null)
                                                                              {
                                                                                  if (Obj.Adjunto != null)
                                                                                  {
                                                                                      AdjuntoRepository _adjuntoRepo = new AdjuntoRepository();
                                                                                      //Elimar archivo
                                                                                      if (Obj.Adjunto.nombre == "eliminar")
                                                                                      {
                                                                                          int id = Convert.ToInt32(Obj.AdjuntoId);
                                                                                          result.AdjuntoId = null;
                                                                                          Obj.AdjuntoId    = null;
                                                                                          await _ctx.SaveChangesAsync();

                                                                                          await _adjuntoRepo.Delete(id);
                                                                                      }
                                                                                      ///Agregar archivo al editar
                                                                                      if (Obj.Adjunto.AdjuntoId == 0)
                                                                                      {
                                                                                          if (result.AdjuntoId != null)
                                                                                          {
                                                                                              var id = result.AdjuntoId;
                                                                                              result.AdjuntoId = null;
                                                                                              await _ctx.SaveChangesAsync();

                                                                                              await _adjuntoRepo.Delete(id);
                                                                                          }
                                                                                          Adjunto key = await _adjuntoRepo.CreateAd(Obj.Adjunto);

                                                                                          Obj.AdjuntoId = key.AdjuntoId;
                                                                                      }
                                                                                  }

                                                                                  _ctx.Entry(result).CurrentValues.SetValues(Obj);

                                                                                  await _ctx.SaveChangesAsync();


                                                                                  PersonasRepository prep = new PersonasRepository();
                                                                                  Personas           p    = await prep.GetByClave(Obj.ClavePersona);

                                                                                  p.ultimaActualizacion = DateTime.Now;
                                                                                  await prep.Update(p);
                                                                              }
                                                                          }
                                                                          catch (Exception e)
                                                                          {
                                                                              throw new Exception(e.Message, e);
                                                                          }
                                                                      }
Beispiel #13
0
        public async Task Update(Publicacion Obj)// UpdateSolicitud
        {
            try
            {
                var result = await _ctx.Publicacion.FirstOrDefaultAsync(e => e.PublicacionId == Obj.PublicacionId);

                // if(await ValidarDuplicados(Obj))
                // {
                //     throw new ApplicationException("Intente cambiar la revista asociada, la fecha de publicación o el número de páginas");
                // }
                if (Obj.EstadoFlujoId == 1 && result.EstadoFlujoId == 3)
                {
                    await new NuevoOCRepository().DeleteId("ArtículoCH", result.PublicacionId + "");
                }
                if (result != null)
                {
                    if (Obj.Adjunto != null)
                    {
                        AdjuntoRepository _adjuntoRepo = new AdjuntoRepository();
                        if (Obj.Adjunto.nombre == "eliminar")
                        {
                            int id = Convert.ToInt32(Obj.Adjunto.AdjuntoId);
                            Obj.AdjuntoId = null;
                            _ctx.Entry(result).CurrentValues.SetValues(Obj);
                            await _ctx.SaveChangesAsync();

                            await _adjuntoRepo.Delete(id);
                        }
                        ///Agregar archivo al editar
                        if (Obj.Adjunto.AdjuntoId == 0)
                        {
                            if (result.AdjuntoId != null)
                            {
                                var id = result.AdjuntoId;
                                Obj.AdjuntoId = null;
                                _ctx.Entry(result).CurrentValues.SetValues(Obj);
                                await _ctx.SaveChangesAsync();

                                await _adjuntoRepo.Delete(id);
                            }
                            Adjunto key = await _adjuntoRepo.CreateAd(Obj.Adjunto);

                            Obj.AdjuntoId = key.AdjuntoId;
                        }
                    }

                    _ctx.Entry(result).CurrentValues.SetValues(Obj);

                    await _ctx.SaveChangesAsync();
                }

                //if (Obj.EstadoFlujoId == 3)
                //{
                //    await new NuevoOCRepository().Create(
                //    new NuevoOC("MT",
                //               "ARTÍCULO",
                //    Obj.TituloPublicacion,
                //    "indexMT.html#/PublicacionDetails/" + Obj.PublicacionId
                //        ));
                //}


                PersonasRepository prep = new PersonasRepository();
                Personas           p    = await prep.GetByClave(Obj.ClavePersona);

                p.ultimaActualizacion = DateTime.Now;
                await prep.Update(p);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
                                                              public async Task <IHttpActionResult> Update(PersonalProyecto model)
                                                              {
                                                                  if (!ModelState.IsValid)
                                                                  {
                                                                      return(BadRequest(ModelState));
                                                                  }

                                                                  try { log.Info(new MDCSet(this.ControllerContext.RouteData));
                                                                        if (model.Adjunto != null)
                                                                        {
                                                                            //Elimar archivo
                                                                            if (model.Adjunto.nombre == "eliminar")
                                                                            {
                                                                                int id = Convert.ToInt32(model.AdjuntoId);
                                                                                model.AdjuntoId = null;
                                                                                await _entityRepo.Update(model);

                                                                                await _adjuntoRepo.Delete(id);

                                                                                return(Ok());
                                                                            }
                                                                            ///Agregar archivo al editar
                                                                            if (model.Adjunto.AdjuntoId == 0)
                                                                            {
                                                                                Adjunto key = await _adjuntoRepo.CreateAd(model.Adjunto);

                                                                                model.AdjuntoId         = key.AdjuntoId;
                                                                                model.Adjunto.AdjuntoId = key.AdjuntoId;
                                                                                await _entityRepo.Update(model);

                                                                                return(Ok(key));
                                                                            }
                                                                        }
                                                                        //solución de ALAN replicada
                                                                        if (model.Adjunto != null)
                                                                        {
                                                                            model.AdjuntoId = model.Adjunto.AdjuntoId;
                                                                        }
                                                                        await _entityRepo.Update(model);

                                                                        return(Ok(model)); }
                                                                  catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e);
                                                                                        return(InternalServerError(e)); }
                                                              }
Beispiel #15
0
        public async Task Update(Capitulos model)
        {
            try
            {
                var _model = await _db.dbSetCapitulos.FirstOrDefaultAsync(e => e.CapitulosId == model.CapitulosId);

                if (_model != null)
                {
                    foreach (var item in model.EditoresCapitulo)
                    {
                        if (item.EditoresCapituloId == 0)
                        {
                            var result = _db.dbSetEditoresCapitulo.Add(item);
                            await _db.SaveChangesAsync();
                        }
                        else
                        {
                            if (item.Editor_Nombre.Equals("eliminar"))
                            {
                                var result = await _db.dbSetEditoresCapitulo.FirstOrDefaultAsync(e => e.EditoresCapituloId == item.EditoresCapituloId);

                                if (result != null)
                                {
                                    _db.dbSetEditoresCapitulo.Remove(result);
                                    await _db.SaveChangesAsync();
                                }
                            }
                        }
                    }

                    foreach (var item in model.AutorExternoCapitulo)
                    {
                        if (item.AutorExternoCapituloId == 0)
                        {
                            var result = _db.dbSetAutorExternoCapitulo.Add(item);
                            await _db.SaveChangesAsync();
                        }
                        else
                        {
                            if (item.Nombre.Equals("eliminar"))
                            {
                                var result = await _db.dbSetAutorExternoCapitulo.FirstOrDefaultAsync(e => e.AutorExternoCapituloId == item.AutorExternoCapituloId);

                                if (result != null)
                                {
                                    _db.dbSetAutorExternoCapitulo.Remove(result);
                                    await _db.SaveChangesAsync();
                                }
                            }
                        }
                    }

                    foreach (var item in model.AutorInternoCapitulo)
                    {
                        if (item.AutorInternoCapituloId == 0)
                        {
                            var result = _db.dbSetAutorInternoCapitulo.Add(item);
                            await _db.SaveChangesAsync();
                        }
                        else
                        {
                            if (item.NombreCompleto.Equals("eliminar"))
                            {
                                var result = await _db.dbSetAutorInternoCapitulo.FirstOrDefaultAsync(e => e.AutorInternoCapituloId == item.AutorInternoCapituloId);

                                if (result != null)
                                {
                                    _db.dbSetAutorInternoCapitulo.Remove(result);
                                    await _db.SaveChangesAsync();
                                }
                            }
                        }
                    }


                    if (model.Adjunto != null)
                    {
                        try
                        {
                            AdjuntoRepository adjuntoRepo = new AdjuntoRepository();

                            if (_model.AdjuntoId != null)  //Elimina el adjunto anterior (el que esta en la base de datos)
                            {
                                var id = _model.AdjuntoId;
                                _model.AdjuntoId = null;

                                await _db.SaveChangesAsync();

                                await adjuntoRepo.Delete(id);

                                await _dbGen.SaveChangesAsync();
                            }

                            var adjunto = await adjuntoRepo.CreateAd(model.Adjunto);

                            model.AdjuntoId = adjunto.AdjuntoId;
                            //await _dbGen.SaveChangesAsync();

                            if (model.EstadoFlujoId == 3)
                            {
                                await new NuevoOCRepository().Create(
                                    new NuevoOC("MT", "CAPITULO", model.TituloCapitulo,
                                                "indexMT.html#/CapituloDetails/" + model.CapitulosId
                                                ));
                            }
                        }
                        catch (Exception e)
                        {
                            throw new Exception(e.Message, e);
                        }
                    }
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();


                    PersonasRepository prep = new PersonasRepository();
                    Personas           p    = await prep.GetByClave(model.ClavePersona);

                    p.ultimaActualizacion = DateTime.Now;
                    await prep.Update(p);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }