Пример #1
0
        public async Task <ActionResult> Delete(string id)
        {
            try
            {
                UserApp user = await UserManagerApp.FindByIdAsync(id);

                IdentityResult result = await UserManagerApp.DeleteAsync(user);

                if (result.Succeeded)
                {
                    // Success("User Successfuly deleted!");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //Danger("Failed! Something was wrong!");
                    ModelState.AddModelError("", "error");
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                //Danger("Failed! Something was wrong!");
                throw;
            }
        }
Пример #2
0
        public async Task <ActionResult> ChangePassword(string confirmPassword, string newPassword,
                                                        string currentPassword)
        {
            try
            {
                var hashedPassword = UserManagerApp.PasswordHasher.HashPassword(currentPassword);
                var user           = await UserManagerApp.FindByIdAsync(this.User.Identity.GetUserId());

                if (newPassword == confirmPassword)
                {
                    IdentityResult result =
                        await
                        UserManagerApp.ChangePasswordAsync(User.Identity.GetUserId(), currentPassword, newPassword);

                    if (result.Succeeded)
                    {
                        //  Success("Password updated succesfully");
                        return(RedirectToAction("Index", "Home"));
                    }
                }

                //  Danger("Something was wrong");
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #3
0
        public async Task <ActionResult> Profile(UserApp user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (user.Id == User.Identity.GetUserId())
                    {
                        UserApp oldUser = await UserManagerApp.FindByIdAsync(user.Id);

                        if (oldUser != null)
                        {
                            oldUser.UserName    = user.UserName;
                            oldUser.Email       = user.Email;
                            oldUser.PhoneNumber = user.PhoneNumber;
                            IdentityResult result = await UserManagerApp.UpdateAsync(oldUser);

                            if (result.Succeeded)
                            {
                                // Success("User Updated", true);
                                return(RedirectToAction("Index"));
                            }
                            else
                            {
                                // Danger("Failed! Something was wrong!");
                                result.Errors.ToList().ForEach(err => ModelState.AddModelError("", err));
                                return(View(user));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "There Isn't any role like this id");
                            return(View(new UserApp()));
                        }
                    }
                    // Danger("Failed! Something was wrong!");
                    return(View());
                }
                else
                {
                    // Warning("Model is not valid!");
                    return(View(user));
                }
            }
            catch (Exception)
            {
                //   Danger("Failed! Something was wrong!");
                throw;
            }
        }
Пример #4
0
        public async Task <ActionResult> Edit(string id)
        {
            UserApp user = await UserManagerApp.FindByIdAsync(id);

            if (user != null)
            {
                return(View(user));
            }
            else
            {
                ModelState.AddModelError("", "There Isn't any role like this id");
                return(View(new UserApp()));
            }
        }
Пример #5
0
        public async Task <ActionResult> Profile(string id)
        {
            try
            {
                if (id == User.Identity.GetUserId())
                {
                    UserApp user = await UserManagerApp.FindByIdAsync(id);

                    return(View(user));
                }

                // Danger("Failed! Something was wrong!");
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception)
            {
                throw;
            }
        }