Ejemplo n.º 1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 2
0
 public void Dispose()
 {
     db.Dispose();
 }
Ejemplo n.º 3
0
 public void Dispose()
 {
     userContext.Dispose();
     db.Dispose();
 }
Ejemplo n.º 4
0
        public ActionResult Edit([Bind(Include = "UserId,UserName,Nickname,FirstName,LastName,Phone,Picture,PictureFile")] User user)
        {
            if (string.IsNullOrEmpty(user.FirstName) || user.FirstName.Trim() == string.Empty)
            {
                ModelState.AddModelError("FirstName", "This field is required");
            }

            if (string.IsNullOrEmpty(user.LastName) || user.LastName.Trim() == string.Empty)
            {
                ModelState.AddModelError("LastName", "This field is required");
            }

            if (string.IsNullOrEmpty(user.Phone) || user.Phone.Trim() == string.Empty)
            {
                ModelState.AddModelError("Phone", "This field is required");
            }

            if (ModelState.IsValid)
            {
                BnBContext db2         = new BnBContext();
                User       currentUser = db2.Users.Find(user.UserId);
                if (currentUser.UserName != user.UserName)
                {
                    UsersHelper.UpdateUserName(currentUser.UserName, user.UserName);
                }
                if ((currentUser.FirstName != user.FirstName) ||
                    (currentUser.LastName != user.LastName) ||
                    (currentUser.Nickname != user.Nickname) ||
                    (currentUser.UserName != user.UserName))
                {
                    Customer customer = db.Customers
                                        .Where(c => c.UserId == user.UserId && c.IsAccountOwner == true)
                                        .FirstOrDefault();
                    customer.CustomerName    = user.Name;
                    db.Entry(customer).State = EntityState.Modified;
                }

                db2.Dispose();

                if (user.PictureFile != null)
                {
                    var    folder         = "~/Content/Pictures";
                    string pic            = string.Format("{0}{1}", user.UserId, Path.GetExtension(user.PictureFile.FileName));
                    bool   uploadResponse = FilesHelper.UploadImage(user.PictureFile, folder, pic);
                    if (uploadResponse)
                    {
                        user.Picture = string.Format("{0}/{1}", folder, pic);
                    }
                }

                db.Entry(user).State = EntityState.Modified;

                Response response = DBHelper.SaveChanges(db);
                if (response.Succeeded)
                {
                    return(RedirectToAction("Details", new { id = user.UserId }));
                }
                ModelState.AddModelError(string.Empty, response.Message);
            }
            return(View(user));
        }