Beispiel #1
0
        //guardardocumento
        //Todo frontend
        //guardardocumento
        public ResponseModel GuardarDocumento(HttpPostedFileBase rar)
        {
            var    rm            = new ResponseModel();
            string nombrearchivo = "";

            try
            {
                using (var db = new ModeloDatos())
                {
                    db.Configuration.ValidateOnSaveEnabled = false;
                    var Doc = db.Entry(this);
                    Doc.State = System.Data.Entity.EntityState.Modified;
                    if (rar != null)
                    {
                        string extension       = Path.GetExtension(rar.FileName).ToLower();
                        var    filtroextension = new[] { ".rar" };
                        var    extensiones     = Path.GetExtension(rar.FileName);

                        if (filtroextension.Contains(extensiones))
                        {
                            string archivo = Path.GetFileName(rar.FileName);
                            nombrearchivo = Path.GetFileName(rar.FileName);
                            rar.SaveAs(HttpContext.Current.Server.MapPath("~/Server/Docs/" + archivo));
                            this.nombre = archivo;

                            this.tamanio = rar.ContentLength.ToString();
                            this.nombre  = nombrearchivo;

                            string   value      = extension;
                            char     delimiter  = '.';
                            string[] substrings = value.Split(delimiter);
                            foreach (var substring in substrings)
                            {
                                this.extension = substring;
                            }

                            this.estado = "Activo";
                        }
                    }

                    ///  else rar.Property(X => X.nombre).IsModified = false;
                    //if (this.estado == null) rar.Property(x => x.estado).IsModified = false;
                    db.Entry(this).State = EntityState.Added; //si el valor es  cero va a agregar
                    db.SaveChanges();
                    rm.SetResponse(true);
                }
            }
            catch (DbEntityValidationException e)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
            return(rm);
        }
Beispiel #2
0
 public void Guardar()
 {
     try
     {
         using (var db = new ModeloDatos())
         {
             if (this.premio_id > 0)
             {
                 db.Entry(this).State = EntityState.Modified;
             }
             else
             {
                 db.Entry(this).State = EntityState.Added;
             }
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
Beispiel #3
0
        //metodo guardar
        public void Guardar()
        {
            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
                    }
                    else
                    {
                        db.Entry(this).State = EntityState.Added; //si el valor es  cero va a agregar
                    }
                    db.SaveChanges();
                }
            }

            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #4
0
 //metodo guardar
 public void Guardar()
 {
     try
     {
         using (var db = new ModeloDatos())
         {
             if (this.tipopersona_id > 0)
             {
                 db.Entry(this).State = EntityState.Modified;
             }
             //si no existiera
             else
             {
                 db.Entry(this).State = EntityState.Added;
             }
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Beispiel #5
0
 public void Eliminar()
 {
     try
     {
         using (var db = new ModeloDatos())
         {
             db.Entry(this).State = EntityState.Deleted;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
Beispiel #6
0
        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;
            }
        }
Beispiel #7
0
        public void Guardar()
        {
            try
            {
                using (var db = new ModeloDatos())
                {
                    //this.semestre_id es como un "boolean"
                    if (this.persona_id > 0)
                    {
                        db.Entry(this).State = EntityState.Modified;
                    }
                    else
                    {
                        db.Entry(this).State = EntityState.Added;
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Beispiel #8
0
        public void Eliminar()
        {
            try
            {
                using (var db = new ModeloDatos())
                {
                    db.Database.ExecuteSqlCommand(
                        "delete from Documento where proyecto_id = @proyecto_id",
                        new SqlParameter("proyecto_id", this.proyecto_id)
                        );
                    db.Database.ExecuteSqlCommand(
                        "delete from OrdenProyecto where proyecto_id = @proyecto_id",
                        new SqlParameter("proyecto_id", this.proyecto_id)
                        );
                    db.Database.ExecuteSqlCommand(
                        "delete from ProyectoEstudiante where proyecto_id = @proyecto_id",
                        new SqlParameter("proyecto_id", this.proyecto_id)
                        );

                    db.Database.ExecuteSqlCommand(
                        "delete from Evaluacion where proyecto_id = @proyecto_id",
                        new SqlParameter("proyecto_id", this.proyecto_id)
                        );

                    db.Database.ExecuteSqlCommand(
                        "delete from ResultadoEvaluacion where proyecto_id = @proyecto_id",
                        new SqlParameter("proyecto_id", this.proyecto_id)
                        );

                    db.Database.ExecuteSqlCommand(
                        "delete from ResultadoGanadorCategoria where proyecto_id = @proyecto_id",
                        new SqlParameter("proyecto_id", this.proyecto_id)
                        );

                    db.Entry(this).State = EntityState.Deleted;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
 public void Eliminar()
 {
     try
     {
         using (var db = new ModeloDatos())
         {
             db.Database.ExecuteSqlCommand(
                 "delete from CategoriaJurado where categoria_id = @categoria_id",
                 new SqlParameter("categoria_id", this.categoria_id)
                 );
             db.Entry(this).State = EntityState.Deleted;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
 public void Eliminar()
 {
     try
     {
         using (var db = new ModeloDatos())
         {
             db.Database.ExecuteSqlCommand(
                 "delete from ProyectoEstudiante where proyectoestudiante_id = @proyectoestudiante_id",
                 new SqlParameter("proyectoestudiante_id", this.proyectoestudiante_id)
                 );
             db.Entry(this).State = EntityState.Deleted;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
Beispiel #11
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;
     }
 }
Beispiel #12
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.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.clave == null)
                    {
                        Usu.Property(x => x.clave).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);
        }
Beispiel #13
0
        public void Guardar()
        {
            try
            {
                using (var db = new ModeloDatos())
                {
                    var LastRegister = 0;

                    var flag = false;

                    var registro = new OrdenProyecto();

                    if (this.categoria_id > 0)
                    {
                        if (this.OrdenProyecto != null)
                        {
                            flag = true;
                        }

                        db.Database.ExecuteSqlCommand(
                            "DELETE FROM OrdenProyecto WHERE proyecto_id = @proyecto_id",
                            new SqlParameter("proyecto_id", this.proyecto_id)
                            );

                        LastRegister = Convert.ToInt32(db.Database.SqlQuery <decimal>("Select IDENT_CURRENT ('OrdenProyecto')", new object[0]).FirstOrDefault());

                        registro = db.OrdenProyecto
                                   .Where(x => x.proyecto_id == this.proyecto_id).SingleOrDefault();

                        var ordenproyecto = this.OrdenProyecto;
                        this.OrdenProyecto   = null;
                        db.Entry(this).State = EntityState.Modified;
                        this.OrdenProyecto   = ordenproyecto;
                    }
                    else
                    {
                        registro = db.OrdenProyecto
                                   .Where(x => x.proyecto_id == this.proyecto_id).SingleOrDefault();
                        db.Entry(this).State = EntityState.Added;
                    }

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

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Beispiel #14
0
        public void GuardarNuevo()
        {
            try
            {
                using (var db = new ModeloDatos())
                {
                    var LastRegister = 0;

                    var flag = false;

                    var registro = new CategoriaJurado();

                    if (this.categoria_id == 0)
                    {
                        db.Database.ExecuteSqlCommand(
                            "DELETE FROM CategoriaJurado WHERE categoria_id = @categoria_id",
                            new SqlParameter("categoria_id", this.categoria_id)
                            );

                        LastRegister = db.CategoriaJurado
                                       .OrderByDescending(x => x.categoriajurado_id)
                                       .First().categoriajurado_id;

                        registro = db.CategoriaJurado
                                   .Where(x => x.categoria_id == this.categoria_id).SingleOrDefault();

                        var cursodocente = this.CategoriaJurado;

                        flag = true;
                        this.CategoriaJurado = null;
                        db.Database.ExecuteSqlCommand(
                            "insert into Categoria values(@categoria_id,@nombre,@descripcion)",
                            new SqlParameter("categoria_id", this.categoria_id),
                            new SqlParameter("nombre", this.nombre),
                            new SqlParameter("descripcion", this.descripcion)
                            );
                        this.CategoriaJurado = cursodocente;

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

                    if (flag)
                    {
                    }
                    else
                    {
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #15
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;
            }
        }
Beispiel #16
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;
            }
        }