public void CreateUserTest()
 {
     UserController uc = new UserController();
     UserCreateModel model = new UserCreateModel();
     model.UserName = "******";
     model.Password = "******";
     model.FirstName = "Faisal";
     model.LastName = "Khanani";
     model.PhoneNumber = "03332111353";
     model.Email = "*****@*****.**";
     model.RoleName = "SuperAdmin";
     var result = UserHelper.CreateUser(model);
     Assert.IsTrue(result);
 }
        public bool UpdateUser(UserCreateModel model)
        {
            if (!Roles.RoleExists(model.RoleName))
            {
                return false;
            }

            MembershipUser user = Membership.GetUser(model.UserName);
            if (user != null)
            {
                UserProfile up = UserProfile.GetProfile(model.UserName);
                up.FirstName = model.FirstName;
                up.LastName = model.LastName;
                up.PhoneNumber = model.PhoneNumber;
                up.Email = model.Email;
                up.CompanyId = model.CompanyId.Value;
                up.Save();
                if (!Roles.GetRolesForUser(model.UserName).Contains(model.RoleName))
                {
                    Roles.AddUserToRole(model.UserName, model.RoleName);
                }
                return true;
            }

            return false;
        }
        public bool CreateUser(UserCreateModel model)
        {
            if (!Roles.RoleExists(model.RoleName))
            {
                return false;
            }

            MembershipUser user = Membership.GetUser(model.UserName);
            if (user == null)
            {
                MembershipCreateStatus status;
                user = Membership.CreateUser(model.UserName, model.Password, model.Email, model.PasswordQuestion, model.PasswordAnswer, true, out status);
                if (status == MembershipCreateStatus.Success && user != null)
                {
                    UserProfile up = UserProfile.GetProfile(model.UserName);
                    up.FirstName = model.FirstName;
                    up.LastName = model.LastName;
                    up.PhoneNumber = model.PhoneNumber;
                    up.Email = model.Email;
                    up.CompanyId = AuthenticationHelper.CompanyId.Value;
                    up.Save();

                    if (!Roles.GetRolesForUser(model.UserName).Contains(model.RoleName))
                    {
                        Roles.AddUserToRole(model.UserName, model.RoleName);
                    }


                    featureSetAccessService.Insert(new FeatureSetAccess { CompanyId = AuthenticationHelper.CompanyId.Value, CreateBy= AuthenticationHelper.UserId, CreateDate = DateTime.Now, FeatureSetId = model.FeatureSetId, UserId = Guid.Parse(user.ProviderUserKey.ToString()) });

                    return true;
                }
            }

            return false;
        }
 public ActionResult Edit(UserCreateModel model)
 {
     if (ModelState.IsValid)
     {
         if (UpdateUser(model))
         {
             return RedirectToAction("Index");
         }
     }
     return View(model);
 }
 public ActionResult Edit(Guid id)
 {
     var memUser = Membership.GetUser(id);
     var userProfile = UserProfile.GetProfile(memUser.UserName);
     UserCreateModel model = new UserCreateModel();
     model.UserName = memUser.UserName;
     model.FirstName = userProfile.FirstName;
     model.LastName = userProfile.LastName;
     model.PhoneNumber = userProfile.PhoneNumber;
     model.Email = userProfile.Email;
     model.RoleName = Roles.GetRolesForUser(model.UserName)[0];
     model.CompanyId = userProfile.CompanyId;
     return View(model);
 }
 public ActionResult Create()
 {
     List<SelectListItem> fsList = featureSetService.GetAll(AuthenticationHelper.CompanyId.Value, AuthenticationHelper.UserRole).Select(x => new SelectListItem { Text = x.Name, Value =x.Id.ToString() }).ToList();
     UserCreateModel model = new UserCreateModel(fsList);
     return View(model);
 }