Пример #1
0
        public void Guardar(HttpPostedFileBase Foto)
        {
            try
            {
                using (var db = new Model_CM())
                {
                    if (this.id > 0)
                    {
                        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))
                            {
                                this.imagen = id + "_" + DateTime.Now.ToString("MM-dd-yy_H.mm.ss") + this.imagen + extensiones;
                                if (File.Exists(HttpContext.Current.Server.MapPath("~/Uploads/" + imagen)))
                                {
                                    File.Delete(HttpContext.Current.Server.MapPath("~/Uploads/" + imagen));
                                }
                                Foto.SaveAs(HttpContext.Current.Server.MapPath("~/Uploads/" + imagen));
                            }

                            this.clave = HashHelper.MD5(clave);

                            db.Entry(this).State = EntityState.Modified;
                        }
                    }
                    else
                    {
                        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))
                            {
                                this.imagen = id + "_" + DateTime.Now.ToString("MM-dd-yy_H.mm.ss") + this.imagen + extensiones;
                                if (File.Exists(HttpContext.Current.Server.MapPath("~/Uploads/" + imagen)))
                                {
                                    File.Delete(HttpContext.Current.Server.MapPath("~/Uploads/" + imagen));
                                }
                                Foto.SaveAs(HttpContext.Current.Server.MapPath("~/Uploads/" + imagen));
                            }

                            this.clave = HashHelper.MD5(clave);

                            db.Entry(this).State = EntityState.Added;
                        }
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
 public void Guardar()
 {
     try
     {
         using (var db = new Model_CM())
         {
             if (this.id > 0)
             {
                 db.Entry(this).State = EntityState.Modified;
             }
             else
             {
                 db.Entry(this).State = EntityState.Added;
             }
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #3
0
 public void Eliminar()
 {
     try
     {
         using (var db = new Model_CM())
         {
             db.Entry(this).State = EntityState.Deleted;
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }