// GET: AdminManageUser
        public ActionResult Index()
        {
            ShowAdminSidebar();
            var adminUserModelEnum = new AdminManageUserViewModel().VMList();

            return(View(adminUserModelEnum));
        }
 public ActionResult Edit(AdminManageUserViewModel AdminUser)
 {
     using (DHDomoticaDBEntities DHDomoticadbModel = new DHDomoticaDBEntities())
     {
         AdminUser.EditExistingUser(AdminUser.ID);
         ShowAdminSidebar();
         return(RedirectToAction("Index"));
     }
 }
        public async Task <IActionResult> ManageUser(AdminManageUserViewModel model)
        {
            var authResult = await this.CanManageUser(model.Id);

            if (!authResult.allowed)
            {
                return(this.RedirectToAction(authResult.selfManage ? "Login" : "Users", new { authResult.error }));
            }

            if (this.ModelState.IsValid)
            {
                var results = new List <IdentityResult>();
                var user    = authResult.user;

                results.Add(await this._users.SetUserNameAsync(user, model.Username));

                if (model.Password != null || model.ConfirmPassword != null || model.CurrentPassword != null)
                {
                    if (model.Password != null && model.ConfirmPassword != null && model.CurrentPassword != null)
                    {
                        if (model.Password == model.ConfirmPassword)
                        {
                            results.Add(await this._users.ChangePasswordAsync(user, model.CurrentPassword, model.Password));
                        }
                        else
                        {
                            this.ModelState.AddModelError(nameof(model.ConfirmPassword), "New Password doesn't match Confirm Password.");
                        }
                    }
                    else
                    {
                        this.ModelState.AddModelError(nameof(model.Password), "All three password fields must be provided to change the password.");
                    }
                }

                foreach (var error in results.Where(r => !r.Succeeded).SelectMany(r => r.Errors))
                {
                    this.ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            model.CurrentPassword = null;
            model.Password        = null;
            model.ConfirmPassword = null;
            return(this.View(VIEW_MANAGE_USER, model));
        }
        // GET: AdminManageUser/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User user = db.Users.Find(id);

            if (user == null)
            {
                return(HttpNotFound());
            }
            AdminManageUserViewModel adminModel = new AdminManageUserViewModel(user);

            ShowAdminSidebar();
            return(View(adminModel));
        }
 public ActionResult Create(AdminManageUserViewModel adminUserModel)
 {
     //user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);
     if (ModelState.IsValid)
     {
         adminUserModel.CreateNewUser();
         ShowAdminSidebar();
         var adminUserModelEnum = new AdminManageUserViewModel().VMList();
         return(View("Index", adminUserModelEnum));
     }
     else
     {
         ShowAdminSidebar();
         ViewBag.AdminID = new SelectList(db.AdminRights, "AdminID", "Rights", adminUserModel.AdminID);
         return(View("Create", adminUserModel));
     }
 }