public ActionResult SetAvatar(IndexViewModel model, HttpPostedFileBase file) { bool success = false; if(file.ContentLength > 0 && file != null) { var user = UserManager.FindById(User.Identity.GetUserId()); string imagePath = new FileManager().Save(file); model.ImagePath = imagePath; success = UserManager.ChangeUserAvatar(User.Identity.GetUserId(), imagePath); } if(success == false) { return new HttpNotFoundResult(); } return View("Index", model); }
public ActionResult Index(HttpPostedFileBase file) { var userId = User.Identity.GetUserId(); var user = UserManager.GetUser(userId); string currentImagePath = UserManager.GetUserImagePath(userId); bool success = false; string imagePath = string.Empty; if (file != null && file.ContentLength > 0) { imagePath = new FileManager().Save(file); if(String.IsNullOrWhiteSpace(imagePath)) { return RedirectToAction("Index", new { Message = ManageMessageId.AvatarFormatError }); } if (String.IsNullOrEmpty(currentImagePath) == false) { FileManager fileManager = new FileManager(); fileManager.DeleteFile(currentImagePath); } success = UserManager.ChangeUserAvatar(User.Identity.GetUserId(), imagePath); } if(success) { return RedirectToAction("Index", new { Message = ManageMessageId.AvatarChangeSuccess}); } //Error! return View(); }
public ActionResult RemoveAvatar() { var userId = User.Identity.GetUserId(); string imagePath = UserManager.GetUserImagePath(userId); if (String.IsNullOrWhiteSpace(imagePath) == false) { FileManager fileManager = new FileManager(); fileManager.DeleteFile(imagePath); } if(UserManager.RemoveAvatar(userId) == true) { return RedirectToAction("Index", new { Message = ManageMessageId.AvatarRemoveSuccess }); } //Error! return RedirectToAction("Index"); }