Пример #1
0
 //METODO GUARDAR
 public void Guardar(string SiDocente, string siSemestre, bool docente)
 {
     try
     {
         using (var db = new ModeloDatos())
         {
             if (this.persona_id > 0)
             {
                 db.Entry(this).State = EntityState.Modified;
                 Directory.Move(
                     HttpContext.Current.Server.MapPath("~/Server/EPIS/Portafolio/Portafolio_" + siSemestre + "/" + SiDocente),
                     HttpContext.Current.Server.MapPath("~/Server/EPIS/Portafolio/Portafolio_" + siSemestre + "/" + this.dni + "_" + this.nombre + " " + this.apellido));
             }
             else
             {
                 db.Entry(this).State = EntityState.Added;
                 if (docente)
                 {
                     string path = Path.Combine(HttpContext.Current.Server.MapPath("~/Server/EPIS/Portafolio/Portafolio_" + siSemestre),
                                                this.dni + "_" + this.nombre + " " + this.apellido);
                     Directory.CreateDirectory(path);
                 }
             }
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Пример #2
0
        //metodo guardar
        public void Guardar(string sem_ant)
        {
            try
            {
                using (var db = new ModeloDatos())//si existe solo modifica si no existe solo agrega
                {
                    if (this.semestre_id > 0)
                    {
                        db.Entry(this).State = EntityState.Modified; //si el valor es mayor que cero solo modifica
                        Directory.Move(
                            HttpContext.Current.Server.MapPath("~/Server/EPIS/Portafolio/Portafolio_" + sem_ant),
                            HttpContext.Current.Server.MapPath("~/Server/EPIS/Portafolio/Portafolio_" + this.nombre));
                    }
                    else
                    {
                        db.Entry(this).State = EntityState.Added; //si el valor es  cero va a agregar
                        string path = Path.Combine(HttpContext.Current.Server.MapPath("~/Server/EPIS/Portafolio/"), "Portafolio_" + this.nombre);
                        Directory.CreateDirectory(path);
                    }
                    db.SaveChanges();
                }
            }

            catch (Exception ex)
            {
                throw;
            }
        }
Пример #3
0
 //METODO GUARDAR
 public void Guardar()
 {
     try
     {
         using (var db = new ModeloDatos())
         {
             if (this.hojavidadocentefc_id > 0)
             {
                 db.Entry(this).State = EntityState.Modified;
             }
             else
             {
                 db.Entry(this).State = EntityState.Added;
             }
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Пример #4
0
 public void Eliminar()
 {
     try
     {
         using (var db = new ModeloDatos())
         {
             db.Entry(this).State = EntityState.Deleted;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
Пример #5
0
        //METODO GUARDAR
        public void Guardar()
        {
            try
            {
                using (var db = new ModeloDatos())
                {
                    db.Configuration.ValidateOnSaveEnabled = false;

                    //this.semestre_id es como un "boolean"
                    if (this.usuario_id > 0)
                    {
                        db.Entry(this).State = EntityState.Modified;

                        if (this.clave != null)
                        {
                            this.clave = HashHelper.MD5(this.clave);
                        }
                        else
                        {
                            db.Entry(this).Property(x => x.clave).IsModified = false;
                        }
                    }
                    else
                    {
                        this.clave           = HashHelper.MD5(this.clave);
                        db.Entry(this).State = EntityState.Added;
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Пример #6
0
        public void Guardar()
        {
            try
            {
                using (var db = new ModeloDatos())
                {
                    //this.semestre_id es como un "boolean"
                    if (this.plan_id > 0)
                    {
                        db.Entry(this).State = EntityState.Modified;
                    }
                    else
                    {
                        db.Entry(this).State = EntityState.Added;
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Пример #7
0
 public void Eliminar()
 {
     try
     {
         using (var db = new ModeloDatos())
         {
             db.Database.ExecuteSqlCommand(
                 "delete from CursoDocente where curso_cod = @curso_cod",
                 new SqlParameter("curso_cod", this.curso_cod)
                 );
             db.Entry(this).State = EntityState.Deleted;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
Пример #8
0
        public void Guardar()
        {
            System.DateTime dt;
            dt = Convert.ToDateTime(DateTime.Now);

            this.fecha_emision = dt;
            try
            {
                using (var db = new ModeloDatos())
                {
                    if (this.notificacion_id == 0)
                    {
                        db.Entry(this).State = EntityState.Added;
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Пример #9
0
        public ResponseModel GuardarPerfil(HttpPostedFileBase Foto)
        {
            var rm = new ResponseModel();

            try
            {
                using (var db = new ModeloDatos())
                {
                    db.Configuration.ValidateOnSaveEnabled = false;

                    var Usu = db.Entry(this);

                    Usu.State = EntityState.Modified;

                    if (Foto != null)
                    {
                        string extension       = Path.GetExtension(Foto.FileName).ToLower();
                        int    size            = 1024 * 1024 * 7; //7 megas
                        var    filtroextension = new[] { ".jpg", ".jpeg", ".png", ".gif" };
                        var    extensiones     = Path.GetExtension(Foto.FileName);

                        if (filtroextension.Contains(extensiones) && (Foto.ContentLength < size))
                        {
                            string archivo = Path.GetFileName(Foto.FileName);
                            Foto.SaveAs(HttpContext.Current.Server.MapPath("~/Server/Images/" + archivo));
                            this.avatar = archivo;
                        }
                    }
                    else
                    {
                        Usu.Property(x => x.avatar).IsModified = false;
                    }

                    if (this.clave == null)
                    {
                        Usu.Property(x => x.clave).IsModified = false;
                    }
                    else
                    {
                        this.clave = HashHelper.MD5(this.clave);
                    }
                    if (this.usuario_id == 0)
                    {
                        Usu.Property(x => x.usuario_id).IsModified = false;
                    }
                    if (this.persona_id == 0)
                    {
                        Usu.Property(x => x.persona_id).IsModified = false;
                    }
                    if (this.tipousuario == 0)
                    {
                        Usu.Property(x => x.tipousuario).IsModified = false;
                    }
                    if (this.estado == null)
                    {
                        Usu.Property(x => x.estado).IsModified = false;
                    }
                    db.SaveChanges();
                    rm.SetResponse(true);
                }
            }
            catch (DbEntityValidationException e)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
            return(rm);
        }
Пример #10
0
        public void GuardarModificar()
        {
            try
            {
                using (var db = new ModeloDatos())
                {
                    var LastRegister = 0;

                    var flag = false;

                    var registro = new CursoDocente();

                    if (this.curso_cod != null)
                    {
                        db.Database.ExecuteSqlCommand(
                            "DELETE FROM CursoDocente WHERE curso_cod = @curso_cod",
                            new SqlParameter("curso_cod", this.curso_cod)
                            );

                        try
                        {
                            LastRegister = db.CursoDocente
                                           .OrderByDescending(x => x.cursodocente_id)
                                           .First().cursodocente_id;
                        }
                        catch (Exception e)
                        {
                            LastRegister = 0;
                        }

                        registro = db.CursoDocente
                                   .Where(x => x.curso_cod.Contains(this.curso_cod)).SingleOrDefault();

                        var cursodocente = this.CursoDocente;
                        this.CursoDocente    = null;
                        db.Entry(this).State = EntityState.Modified;
                        this.CursoDocente    = cursodocente;
                    }
                    else
                    {
                        registro = db.CursoDocente
                                   .Where(x => x.curso_cod.Contains(this.curso_cod)).SingleOrDefault();
                        db.Entry(this).State = EntityState.Added;
                    }

                    foreach (var c in this.CursoDocente)
                    {
                        if (registro == null)
                        {
                            c.cursodocente_id = LastRegister + 1;
                            db.Entry(c).State = EntityState.Added;
                        }
                        else
                        {
                            c.cursodocente_id = registro.cursodocente_id;
                            db.Entry(c).State = EntityState.Unchanged;
                        }
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Пример #11
0
        public void GuardarNuevo()
        {
            try
            {
                using (var db = new ModeloDatos())
                {
                    var LastRegister = 0;

                    var flag = false;

                    var registro = new CursoDocente();

                    if (this.curso_cod != null)
                    {
                        db.Database.ExecuteSqlCommand(
                            "DELETE FROM CursoDocente WHERE curso_cod = @curso_cod",
                            new SqlParameter("curso_cod", this.curso_cod)
                            );

                        try
                        {
                            LastRegister = db.CursoDocente
                                           .OrderByDescending(x => x.cursodocente_id)
                                           .First().cursodocente_id;
                        }
                        catch (Exception e)
                        {
                            LastRegister = 0;
                        }

                        registro = db.CursoDocente
                                   .Where(x => x.curso_cod.Contains(this.curso_cod)).SingleOrDefault();

                        var d = db.Curso
                                .Where(x => x.curso_cod.Contains(this.curso_cod)).SingleOrDefault();

                        var cursodocente = this.CursoDocente;

                        if (d == null)
                        {
                            flag = true;
                            this.CursoDocente = null;
                            db.Database.ExecuteSqlCommand(
                                "insert into Curso values(@curso_cod,@plan_id,@ciclo_id,@nombre,@credito,@horasteoria,@horaspractica,@totalhoras,@prerequisito,@estado)",
                                new SqlParameter("curso_cod", this.curso_cod),
                                new SqlParameter("plan_id", this.plan_id),
                                new SqlParameter("ciclo_id", this.ciclo_id),
                                new SqlParameter("nombre", this.nombre),
                                new SqlParameter("credito", this.credito),
                                new SqlParameter("horasteoria", this.horasteoria),
                                new SqlParameter("horaspractica", this.horaspractica),
                                new SqlParameter("totalhoras", this.totalhoras),
                                new SqlParameter("prerequisito", this.prerequisito),
                                new SqlParameter("estado", this.estado)
                                );
                            this.CursoDocente = cursodocente;

                            foreach (var c in this.CursoDocente)
                            {
                                db.Database.ExecuteSqlCommand(
                                    "insert into CursoDocente values(@curso_cod,@persona_id)",
                                    new SqlParameter("curso_cod", this.curso_cod),
                                    new SqlParameter("persona_id", c.persona_id)
                                    );
                            }
                        }
                        else
                        {
                            this.CursoDocente    = null;
                            db.Entry(this).State = EntityState.Modified;
                            this.CursoDocente    = cursodocente;
                        }
                    }
                    else
                    {
                        registro = db.CursoDocente
                                   .Where(x => x.curso_cod.Contains(this.curso_cod)).SingleOrDefault();
                        db.Entry(this).State = EntityState.Added;
                    }

                    if (flag)
                    {
                    }
                    else
                    {
                        foreach (var c in this.CursoDocente)
                        {
                            if (registro == null)
                            {
                                c.cursodocente_id = LastRegister + 1;
                                db.Entry(c).State = EntityState.Added;
                            }
                            else
                            {
                                c.cursodocente_id = registro.cursodocente_id;
                                db.Entry(c).State = EntityState.Unchanged;
                            }
                        }

                        db.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }