public ActionResult AddMoney()
 {
     var users = _userService.GetAllUsers();
     var tempData = new TempDataFacade(TempData);
     return string.IsNullOrWhiteSpace(tempData.SuccessMessage) ?
         View(new AddMoneyModel(users)) :
         View(new AddMoneyModel(tempData.SuccessMessage, users));
 }
        public ActionResult AddMoney(AddMoneyModel model)
        {
            if (!ModelState.IsValid)
                return View(new AddMoneyModel(_userService.GetAllUsers()));

            // ReSharper disable once PossibleInvalidOperationException
            var transaction = new ReloadRequest(model.Amount.Value, model.UserId, UserContext.User.Id);

            _transactionService.Reload(transaction);
            var tempData = new TempDataFacade(TempData);
            tempData.SuccessMessage = _userService.GetUser(model.UserId).Name + "'s account has been credited. The current balance is " +
                                      _userService.GetBalance(model.UserId).ToString("C");
            return RedirectToAction("AddMoney");
        }
        public ActionResult MyProfile(MyProfileModel model)
        {
            if (!ModelState.IsValid)
                return View();

            try
            {
                _userService.ChangePassword(UserContext.User.Id, model.OldPassword, model.NewPassword);
            }
            catch (InvalidUserCredentialsException)
            {
                ModelState.AddModelError("", "The old password is invalid.");
                return View();
            }

            var tempData = new TempDataFacade(TempData);
            tempData.SuccessMessage = "Your password has been changed.";
            return RedirectToAction("MyProfile");
        }
 public ActionResult MyProfile()
 {
     var tempData = new TempDataFacade(TempData);
     return string.IsNullOrWhiteSpace(tempData.SuccessMessage) ? View() : View(new MyProfileModel(tempData.SuccessMessage));
 }
 public ActionResult EditAccount(int? selectedUserId)
 {
     var tempData = new TempDataFacade(TempData);
     return View(new EditAccountModel(_userService.GetAllUsers(), selectedUserId) { SuccessMessage = tempData.SuccessMessage });
 }
        public ActionResult CreateAccount(CreateAccountModel model)
        {
            if (!ModelState.IsValid)
                return View();

            var user = new User(model.Name, model.Username, model.BadgeId, model.IsAdmin);
            try
            {
                _userService.CreateUser(user, model.Username);
            }
            catch (UserExistsException)
            {
                ModelState.AddModelError("", "The user already exists.");
                throw;
            }

            var tempData = new TempDataFacade(TempData);
            tempData.SuccessMessage = "The account was created successfully!";
            return RedirectToAction("CreateAccount");
        }
 public ActionResult CreateAccount()
 {
     var tempData = new TempDataFacade(TempData);
     return string.IsNullOrWhiteSpace(tempData.SuccessMessage) ? View() : View(new CreateAccountModel(tempData.SuccessMessage));
 }
        public ActionResult EditAccount(EditAccountModel model)
        {
            if (!ModelState.IsValid)
                return View();

            var user = _userService.GetUser(model.Id);
            user.IsAdmin = model.IsAdmin;
            if (!string.IsNullOrWhiteSpace(model.BadgeId))
                user.BadgeId = model.BadgeId;
            if (!string.IsNullOrWhiteSpace(model.Name))
                user.Name = model.Name;
            if (!string.IsNullOrWhiteSpace(model.Username))
                user.Username = model.Username;
            if (!string.IsNullOrWhiteSpace(model.Username))
                user.DiscountPercentage = Math.Max(MinDiscount, Math.Min(MaxDiscount, model.DiscountPercentage));
            if (!string.IsNullOrWhiteSpace(model.Password))
                _userService.ResetPassword(user, model.Password);

            var tempData = new TempDataFacade(TempData);
            tempData.SuccessMessage = model.Name + "'s account has been updated.";
            return RedirectToAction("EditAccount", new { selectedUserId = model.Id });
        }