public async Task Update(SolicitudAccesoITF model)
        {
            try
            {
                var _model = await _db.dbSetSolicitudAccesoITF.FirstOrDefaultAsync(e => e.SolicitudAccesoITFId == model.SolicitudAccesoITFId);

                if (_model != null)
                {
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Esempio n. 2
0
        public async Task Update(AdjuntoITFInsumo model)
        {
            try
            {
                var _model = await _db.dbSetAdjuntoITFInsumos.FirstOrDefaultAsync(e => e.AdjuntoITFInsumoId == model.AdjuntoITFInsumoId);

                if (_model != null)
                {
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Esempio n. 3
0
        public async Task Update(TipoCurso model)
        {
            try
            {
                var _model = await _db.dbSetCAT_TipoCurso.FirstOrDefaultAsync(e => e.TipoCursoId == model.TipoCursoId);

                if (_model != null)
                {
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
        public async Task Update(CalifResultadosFinancieros model)
        {
            try
            {
                var _model = await _db.dbSetCAT_CalifResultadosFinancieros.FirstOrDefaultAsync(e => e.CalifResultadosFinancierosId == model.CalifResultadosFinancierosId);

                if (_model != null)
                {
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
        public async Task Update(BitacoraITFDescarga model)
        {
            try
            {
                var _model = await _db.dbSetBitacoraITFDescarga.FirstOrDefaultAsync(e => e.BitacoraITFDescargaId == model.BitacoraITFDescargaId);

                if (_model != null)
                {
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
        public async Task Update(SoftwarePersonal model)
        {
            try
            {
                model.TipoAccesoCat = null;
                model.TipoSoftware  = null;
                var _model = await _db.dbSetSoftwarePersonal.Where(x => x.SoftwarePersonalId == model.SoftwarePersonalId).FirstOrDefaultAsync();

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

                            await new AdjuntoRepository().Delete(id);
                        }
                        var idManuUsuario = await CreateAdjuntoSwMT(model.AdjuntoManualUsuario);

                        model.ManualUsuario = idManuUsuario;
                    }
                    else
                    {
                        _db.dbSetAdjuntoOfMT.Attach(model.AdjuntoManualUsuario);
                        _db.Entry(model.AdjuntoManualUsuario).State = EntityState.Modified;
                        await _db.SaveChangesAsync();
                    }
                }
                catch (Exception ex) {
                    _db = new MT_Context();
                }
                try
                {
                    if (model.ManualTecnico == null)
                    {
                        if (_model.ManualTecnico != null)
                        {
                            var id = _model.ManualTecnico;
                            _model.ManualTecnico = null;
                            await _db.SaveChangesAsync();

                            await new AdjuntoRepository().Delete(id);
                        }
                        var idManuTecnico = await CreateAdjuntoSwMT(model.AdjuntoManualTecnico);

                        model.ManualTecnico = idManuTecnico;
                    }
                    else
                    {
                        _db.dbSetAdjuntoOfMT.Attach(model.AdjuntoManualTecnico);
                        _db.Entry(model.AdjuntoManualTecnico).State = EntityState.Modified;
                        await _db.SaveChangesAsync();
                    }
                }
                catch (Exception ex) { _db = new MT_Context(); }
                try
                {
                    if (model.CodigoFuente == null)
                    {
                        if (_model.CodigoFuente != null)
                        {
                            var id = _model.CodigoFuente;
                            _model.CodigoFuente = null;
                            await _db.SaveChangesAsync();

                            await new AdjuntoRepository().Delete(id);
                        }
                        var idcodFuente = await CreateAdjuntoSwMT(model.AdjuntoCodigoFuente);

                        model.CodigoFuente = idcodFuente;
                    }
                    else
                    {
                        _db.dbSetAdjuntoOfMT.Attach(model.AdjuntoCodigoFuente);
                        _db.Entry(model.AdjuntoCodigoFuente).State = EntityState.Modified;
                        await _db.SaveChangesAsync();
                    }
                }
                catch (Exception ex) { _db = new MT_Context(); }

                foreach (var a in model.Autores)
                {
                    if (a.AutorSoftwareId < 1)
                    {
                        try
                        {
                            a.SoftwarePersonalId = model.SoftwarePersonalId;
                            _db.dbSetAutorSoftware.Add(a);
                            await _db.SaveChangesAsync();
                        }
                        catch (Exception ex1)
                        {
                            _db = new MT_Context();
                        }
                    }
                }


                if (model != null)
                {
                    _db.dbSetSoftwarePersonal.Attach(_model);
                    _db.Entry(model).State = EntityState.Detached;
                    _db.Entry(_model).CurrentValues.SetValues(model);

                    //_db.Entry(_model).State = EntityState.Detached;
                    //_db.dbSetSoftwarePersonal.Attach(model);
                    //_db.Entry(model).State = EntityState.Modified;

                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Esempio n. 7
0
        public async Task Update(CursosPersonal model)
        {
            try
            {
                var _model = await _db.dbSetCursosPersonal
                             .FirstOrDefaultAsync(e => e.CursosPersonalId == model.CursosPersonalId);

                if (_model != null)
                {
                    foreach (var adjuntoCursosPersonal in model.AdjuntoCursosPersonal)
                    {
                        if (adjuntoCursosPersonal.Adjunto != null)
                        {
                            try
                            {
                                if (adjuntoCursosPersonal.Adjunto.AdjuntoId < 1) //NUEVO ADJUNTO
                                {
                                    _dbGen.dbSetAdjuntos.Add(adjuntoCursosPersonal.Adjunto);
                                    await _dbGen.SaveChangesAsync(); //guardar el adjunto

                                    adjuntoCursosPersonal.AdjuntoId        = adjuntoCursosPersonal.Adjunto.AdjuntoId;
                                    adjuntoCursosPersonal.CursosPersonalId = model.CursosPersonalId;
                                    //guardar nuevo adjuntoCursosPersonal
                                    _db.dbSetAdjuntoCursosPersonal.Add(adjuntoCursosPersonal);
                                    await _db.SaveChangesAsync(); //guardar el adjunto
                                }
                                else //adjunto existente: actualizar el adjunto
                                {
                                    var _modelAdjunto = await _dbGen.dbSetAdjuntos.FirstOrDefaultAsync(e => e.AdjuntoId == adjuntoCursosPersonal.Adjunto.AdjuntoId);

                                    _dbGen.Entry(_modelAdjunto).CurrentValues.SetValues(adjuntoCursosPersonal.Adjunto);
                                    await _dbGen.SaveChangesAsync();
                                }
                            }
                            catch (Exception e)
                            {
                                throw new Exception(e.Message, e);
                            }
                        }
                    }
                    foreach (var autoresCursosPersonal in model.AutoresCursosPersonal)
                    {
                        try
                        {
                            if (autoresCursosPersonal.AutoresCursosPersonalId < 1)     //NUEVO Autor
                            {
                                autoresCursosPersonal.Autor_ClavePersona      = autoresCursosPersonal.Autor_ClavePersona;
                                autoresCursosPersonal.Autor_Nombre            = autoresCursosPersonal.Autor_Nombre;
                                autoresCursosPersonal.CursosPersonalId        = model.CursosPersonalId;
                                autoresCursosPersonal.AutoresCursosPersonalId = autoresCursosPersonal.AutoresCursosPersonalId;
                                //guardar nuevo adjuntoCursosPersonal
                                _db.dbSetAutoresCursosPersonal.Add(autoresCursosPersonal);
                                await _db.SaveChangesAsync(); //guardar el adjunto
                            }
                            else                              //adjunto existente: actualizar el adjunto
                            {
                                var _modelAutores = await _db.dbSetAutoresCursosPersonal.FirstOrDefaultAsync(e => e.AutoresCursosPersonalId == autoresCursosPersonal.AutoresCursosPersonalId);

                                _db.Entry(_modelAutores).CurrentValues.SetValues(autoresCursosPersonal);
                                await _db.SaveChangesAsync();
                            }
                        }
                        catch (Exception e)
                        {
                            throw new Exception(e.Message, e);
                        }
                    }
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Esempio n. 8
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);
            }
        }