public JsonResult EditedEmailExist(string email)
        {
            string emailError;

            if (!AccountDbAccess.IsExistingEmail(email, out emailError))
            {
                return(Json(emailError, JsonRequestBehavior.AllowGet));
            }
            return(Json(" ", JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddUser(AddUserModel model)
        {
            string emailError;

            model.groupList = (List <ItemsList>)TempData["groupList"];
            TempData.Keep();

            if (!AccountDbAccess.IsExistingEmail(model.Email, out emailError))
            {
                ModelState.AddModelError("Email", "This email address is already used for another user. Please use a unique email address.");
            }

            if (ModelState.IsValid)
            {
                int createdUserId = 1;
                int msg;

                string temporaryPswd = CommonFunctions.CreatePassword();

                if (temporaryPswd != null)
                {
                    AccountDbAccess.AddNewuser(model.Email, temporaryPswd, model.FirstName, model.LastName, model.Email, model.Phone, Convert.ToInt32(model.selectedGroupId), createdUserId, out msg);

                    if (msg == 0)
                    {
                        //Send mail to created user with username and password
                        if (!SubFunctions.SendNewAccountMail(model.Email, model.FirstName, model.LastName, model.Email, temporaryPswd))
                        {
                            //Show email error msg here
                        }
                        return(JavaScript("window.top.location.href ='" + Url.Action("Index", "UserManagement", new { area = "User" }) + "';"));
                    }
                    else
                    {
                        return(PartialView(model));
                    }
                }
                else
                {
                    return(PartialView(model));
                }
            }
            else
            {
                return(PartialView(model));
            }
        }