Esempio n. 1
0
        public void Guardar(HttpPostedFileBase file, string extensionAntigua)
        {
            try
            {
                using (var db = new Model_Sistema())
                {
                    var doc = db.Entry(this);

                    if (this.documento_id > 0)
                    {
                        db.Entry(this).State = EntityState.Modified;
                    }
                    else
                    {
                        db.Entry(this).State = EntityState.Added;
                    }

                    db.SaveChanges();

                    if (File.Exists(HttpContext.Current.Server.MapPath("~/Uploads/Documents/" + documento_id + extensionAntigua)))
                    {
                        File.Delete(HttpContext.Current.Server.MapPath("~/Uploads/Documents/" + documento_id + extensionAntigua));
                    }

                    file.SaveAs(HttpContext.Current.Server.MapPath("~/Uploads/Documents/" + documento_id + extension));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
 public void Eliminar()
 {
     using (var db = new Model_Sistema())
     {
         if (this.persona_id > 0)
         {
             db.Entry(this).State = EntityState.Deleted;
             db.SaveChanges();
         }
     }
 }
Esempio n. 3
0
 public void Guardar()
 {
     try
     {
         using (var db = new Model_Sistema())
         {
             if (this.persona_id > 0)
             {
                 db.Entry(this).State = EntityState.Modified;
             }
             else
             {
                 db.Entry(this).State = EntityState.Added;
             }
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 4
0
 public void Eliminar()
 {
     try
     {
         using (var db = new Model_Sistema())
         {
             if (this.categoria_id > 0)
             {
                 db.Entry(this).State = EntityState.Deleted;
                 db.SaveChanges();
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 5
0
        public ResponseModel GuardarPerfil(Persona persona)
        {
            var rm = new ResponseModel();

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

                var per = db.Entry(this);

                per.State = EntityState.Modified;

                if (persona != null)
                {
                    if (this.persona_id == 0)
                    {
                        per.Property(x => x.persona_id).IsModified = false;
                    }
                    if (this.estado == null)
                    {
                        per.Property(x => x.estado).IsModified = false;
                    }
                    if (this.dni == null)
                    {
                        per.Property(x => x.dni).IsModified = false;
                    }
                    if (this.apellido == null)
                    {
                        per.Property(x => x.apellido).IsModified = false;
                    }
                    if (this.nombre == null)
                    {
                        per.Property(x => x.nombre).IsModified = false;
                    }


                    db.SaveChanges();
                    rm.SetResponse(true);
                }
            }

            return(rm);
        }
Esempio n. 6
0
        public ResponseModel GuardarPerfil(HttpPostedFileBase Foto)
        {
            var rm = new ResponseModel();

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

                    var usu = db.Entry(this);
                    usu.State = EntityState.Modified;

                    if (Foto != null)
                    {
                        const int size            = 1024 * 1024 * 5;
                        var       filtroextension = new[] { ".jpg", ".jpeg", ".png", ".gif" };
                        var       extensiones     = Path.GetExtension(Foto.FileName);

                        if (filtroextension.Contains(extensiones) && (Foto.ContentLength <= size))
                        {
                            avatar = usuario_id + "_avatar" + extensiones;
                            Foto.SaveAs(HttpContext.Current.Server.MapPath("~/Uploads/" + avatar));
                        }
                        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.usuario1 == null)
                        {
                            usu.Property(x => x.usuario1).IsModified = false;
                        }
                        if (this.nivel == null)
                        {
                            usu.Property(x => x.nivel).IsModified = false;
                        }
                        if (this.estado == null)
                        {
                            usu.Property(x => x.estado).IsModified = false;
                        }
                        if (this.clave == null)
                        {
                            usu.Property(x => x.clave).IsModified = false;
                        }

                        db.SaveChanges();
                        rm.SetResponse(true);
                    }
                }
            }
            catch (DbEntityValidationException)
            {
                throw;
            }

            return(rm);
        }