Example #1
0
        public async Task <IActionResult> ChangePassword(FormUserViewModel model)
        {
            var userPoco = await this.UserService.GetUserById(model.UserId);

            await this.UserService.ChangePassword(userPoco, model.Password);

            return(this.RedirectToAction("All"));
        }
Example #2
0
        public async Task <IActionResult> ChangePassword(int id)
        {
            var user = await this.UserService.GetUserById(id);

            if (user == null)
            {
                return(this.RedirectToAction("All"));
            }

            var model = new FormUserViewModel
            {
                UserId   = user.UserId,
                Username = user.Name
            };

            return(this.View(model));
        }
Example #3
0
        public async Task <IActionResult> Create(FormUserViewModel model)
        {
            if (!CustomValidator.Validate(model))
            {
                return(this.View(model));
            }

            if (!(await this.UserService.IsUsernameFree(model.Username)))
            {
                model.ErrorMessages = new List <string>(model.ErrorMessages)
                {
                    "Username is taken!"
                }.ToArray();
                return(this.View(model));
            }

            await this.UserService.CreateUser(model.Username, model.Password);

            return(this.RedirectToAction("All"));
        }