コード例 #1
0
        public ResponseModel UploadFoto(HttpPostedFileBase foto)
        {
            var rm = new ResponseModel();

            try
            {
                using (var dbventas = new BasedeDatos())
                {
                    dbventas.Configuration.ValidateOnSaveEnabled = false;

                    var eUsuario = dbventas.Entry(this);
                    eUsuario.State = EntityState.Modified;

                    if (foto != null)
                    {
                        string archivo = Path.GetFileName(foto.FileName) + Path.GetExtension(foto.FileName);

                        foto.SaveAs(HttpContext.Current.Server.MapPath("~/Uploads/" + archivo));

                        this.FOTO = archivo;
                    }
                    else
                    {
                        eUsuario.Property(x => x.FOTO).IsModified = false;
                    }

                    if (this.NOMBREUSU == null)
                    {
                        eUsuario.Property(x => x.NOMBREUSU).IsModified = false;
                    }
                    if (this.PASSWORD == null)
                    {
                        eUsuario.Property(x => x.PASSWORD).IsModified = false;
                    }

                    dbventas.SaveChanges();
                    rm.SetResponse(true);
                }
            } catch (DbEntityValidationException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(rm);
        }
コード例 #2
0
 public void Eliminar()
 {
     try
     {
         using (var dbventas = new BasedeDatos())
         {
             dbventas.Entry(this).State = EntityState.Deleted;
             dbventas.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #3
0
 public void Guardar()
 {
     try
     {
         using (var dbventas = new BasedeDatos())
         {
             if (this.IDTIPOUSUARIO > 0)
             {
                 dbventas.Entry(this).State = EntityState.Modified;
             }
             else
             {
                 dbventas.Entry(this).State = EntityState.Added;
             }
             dbventas.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }