Exemplo n.º 1
0
        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;
                if (model.RoleName == UserRoles.SuperAdmin.ToString())
                    up.CompanyId = 0;
                else
                    up.CompanyId = model.CompanyId ?? 0;
                up.Save();

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

                return true;
            }

            return false;
        }
Exemplo n.º 2
0
 public ActionResult Edit(UserCreateModel model)
 {
     if (ModelState.IsValid)
     {
         if (this.UpdateUser(model))
         {
             return RedirectToAction("Index");
         }
     }
     return View(model);
 }
Exemplo n.º 3
0
        //public ActionResult EditFeatureSet()
        //{
        //    FeatureSetModel model = new FeatureSetModel(service.GetSingle(featureSetService.GetSingle()))
        //    return View();
        //}

        //public ActionResult DeleteFeatureSet()
        //{
        //    return View();
        //}

        #region Helper Methods

        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;
                    if (AuthenticationHelper.UserRole != UserRoles.SuperAdmin.ToString())
                        up.CompanyId = AuthenticationHelper.User.CompanyId;
                    up.Save();

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

                    return true;
                }
            }

            return false;
        }
Exemplo n.º 4
0
 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);
 }