Esempio n. 1
0
        public ActionResult AddNew([Bind(Include = "Username,Fullname, Email, Mobile,Enabled")]T_UserProfile userProfile, string password, int RoleID)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    WebSecurity.CreateUserAndAccount(userProfile.UserName, password);
                    UserManagerServices services = new UserManagerServices();
                    T_UserProfile CurrentUser = services.GetByUsername(userProfile.UserName);
                    CurrentUser.Fullname = userProfile.UserName;
                    CurrentUser.Email = userProfile.Email;
                    CurrentUser.Mobile = userProfile.Mobile;
                    CurrentUser.Enabled = userProfile.Enabled;
                    ReturnValue<bool> ret = services.UpdateT_UserProfile(CurrentUser);

                    //Update role
                    services.SetUserInrole(CurrentUser.UserId, RoleID);

                    if (ret.RetValue)
                    {
                        return RedirectToAction("List", "UserManager");
                    }
                }
            }
            catch (MembershipCreateUserException e)
            {
                ModelState.AddModelError("", "Tạo tải khoản không thành công");
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.)
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");

            }
            return View(userProfile);
        }
Esempio n. 2
0
 public ActionResult EditPost(int? userId, int RoleID)
 {
     if (userId == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     UserManagerServices services = new UserManagerServices();
     T_UserProfile userProfile = services.GetByID((int)userId);
     if (TryUpdateModel(userProfile, "",
        new string[] { "Username", "Fullname", "Email", "Mobile", "Enabled" }))
     {
         try
         {
             ReturnValue<bool> ret = services.UpdateT_UserProfile(userProfile);
              //Update role
             services.SetUserInrole(userProfile.UserId, RoleID);
             if (ret.RetValue)
             {
                 return RedirectToAction("List", "UserManager");
             }
         }
         catch (RetryLimitExceededException /* dex */)
         {
             //Log the error (uncomment dex variable name and add a line here to write a log.
             ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
         }
     }
     webpages_Roles Role = services.GetRoleByUserId((int)userId);
     if (Role != null)
     {
         PopulateRole(Role.RoleId);
     }
     else
     {
         PopulateRole(null);
     }
     return View("Edit", userProfile);
 }