Beispiel #1
0
 public ActionResult EditUser(string userEmail)
 {
     UserModel model = new UserModel();
     model.SearchUser(userEmail);
     model.ScreenOpenMode = (int) OpenMode.Edit;
     return View("User", model);
 }
Beispiel #2
0
 /// <summary>
 /// Method to charge properties from other UserModel
 /// </summary>
 /// <param name="user"></param>
 public void Charge(UserModel user)
 {
     this.Email = user.Email;
     this.FirstName = user.FirstName;
     this.LastName = user.LastName;
     this.IsActive = user.IsActive;
     this.SelectedRole = user.SelectedRole;
 }
Beispiel #3
0
 public ActionResult CreateUser()
 {
     UserModel model = new UserModel();
     model.ScreenOpenMode = (int) OpenMode.New;
     return View("User", model);
 }
Beispiel #4
0
        public ActionResult SaveNewUser(UserModel user)
        {
            try
            {
                user.ValidadUser(this);

                //Validate user using Simple membership
                if (ModelState.IsValid)
                {
                    if (user.ScreenOpenMode == (int)OpenMode.New)
                    {
                    string answer = WebSecurity.CreateUserAndAccount(user.Email, user.NewPassword);

                    if (string.IsNullOrEmpty(answer))
                    {
                        Roles.AddUserToRole(user.Email, user.SelectedRole);

                        using (Cotecna.Voc.Business.UsersContext context = new Cotecna.Voc.Business.UsersContext())
                        {
                            Cotecna.Voc.Business.UserProfile currentUser = context.UserProfiles.FirstOrDefault(x => x.UserName == user.Email);
                            currentUser.FirstName = user.FirstName;
                            currentUser.LastName = user.LastName;
                            currentUser.IsActive = user.Active;
                            currentUser.IsInternalUser = false;
                            context.SaveChanges();
                        }
                    }
                    }
                    else
                    {
                        string[] roles = Roles.GetRolesForUser(user.Email);
                        Roles.RemoveUserFromRoles(user.Email, roles);
                        Roles.AddUserToRole(user.Email, user.SelectedRole);

                        //Changing password
                        if (!string.IsNullOrEmpty(user.NewPassword))
                        {
                            var membership = (SimpleMembershipProvider)System.Web.Security.Membership.Provider;
                            var us = membership.GetUser(user.Email, true);
                            string temppassword = us.ResetPassword();
                            WebSecurity.ChangePassword(user.Email, temppassword, user.NewPassword);
                        }

                        //Editing parameters
                        using (Cotecna.Voc.Business.UsersContext context = new Cotecna.Voc.Business.UsersContext())
                        {
                            Cotecna.Voc.Business.UserProfile currentUser = context.UserProfiles.FirstOrDefault(x => x.UserName == user.Email);
                            currentUser.FirstName = user.FirstName;
                            currentUser.LastName = user.LastName;
                            currentUser.IsActive = user.Active;
                            context.SaveChanges();
                        }
                    }
                    return RedirectToAction("Index", "Account");
                }

            }
            catch (MembershipCreateUserException e)
            {
                ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
            }

            return View("User", user);
        }