コード例 #1
0
ファイル: RolesController.cs プロジェクト: RedCamel69/BSG
        public ActionResult DeleteRoleForUser(string UserName, string RoleName)
        {
            var account = new AccountController();
            ApplicationUser user = context.Users.Where(u => u.UserName.Equals(UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();

            if (account.UserManager.IsInRole(user.Id, RoleName))
            {
                account.UserManager.RemoveFromRole(user.Id, RoleName);
                ViewBag.ResultMessage = "Role removed from this user successfully !";
            }
            else
            {
                ViewBag.ResultMessage = "This user doesn't belong to selected role.";
            }
            // prepopulat roles for the view dropdown
            var list = context.Roles.OrderBy(r => r.Name).ToList().Select(rr => new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name }).ToList();
            ViewBag.Roles = list;

            return View("ManageUserRoles");
        }
コード例 #2
0
ファイル: RolesController.cs プロジェクト: RedCamel69/BSG
        public ActionResult GetRoles(string UserName)
        {
            if (!string.IsNullOrWhiteSpace(UserName))
            {
                ApplicationUser user = context.Users.Where(u => u.UserName.Equals(UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
                var account = new AccountController();

                ViewBag.RolesForThisUser = account.UserManager.GetRoles(user.Id);

                // prepopulat roles for the view dropdown
                var list = context.Roles.OrderBy(r => r.Name).ToList().Select(rr => new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name }).ToList();
                ViewBag.Roles = list;
            }

            return View("ManageUserRoles");
        }
コード例 #3
0
ファイル: RolesController.cs プロジェクト: RedCamel69/BSG
        public ActionResult RoleAddToUser(string UserName, string RoleName)
        {
            ApplicationUser user = context.Users.Where(u => u.UserName.Equals(UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
            var account = new AccountController();
            account.UserManager.AddToRole(user.Id, RoleName);

            ViewBag.ResultMessage = "Role created successfully !";

            // prepopulat roles for the view dropdown
            var list = context.Roles.OrderBy(r => r.Name).ToList().Select(rr => new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name }).ToList();
            ViewBag.Roles = list;

            return View("ManageUserRoles");
        }
コード例 #4
0
ファイル: AccountController.cs プロジェクト: RedCamel69/BSG
        public async Task<ActionResult> RegisterAsACoach(RegisterAsCoachViewModel vm)
        {

                if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = vm.UserName };

                user = Mapper.Map<RegisterAsCoachViewModel, ApplicationUser>(vm);

                ////extended prtops
                //user.WebSite = vm.WebSite;
                //user.FirstName = vm.FirstName;
                //user.SecondName = vm.SecondName;
                //user.Phone = vm.Phone;
                //user.MobilePhone = vm.MobilePhone;

                //user.Address = new CoachAddress()
                //{
                //    AddressLine1 = vm.Address.AddressLine1,
                //    AddressLine2=vm.Address.AddressLine2,
                //    AddressLine3=vm.Address.AddressLine3,
                //    City=vm.Address.City,
                //    Country = vm.Address.Country,
                //    County=vm.Address.County,
                //    PostalCode=vm.Address.PostalCode

                //};
                //user.Coach1 = vm.Coach1;
                ////user.Coach2 = vm.Coach2;

                //user.Referral = CoachReferral.Email.ToString();

                //user.Subscriber = false;
                //user.SubscriptionEnd = new DateTime(3000,1,1);

                //user.Roles.Add(new IdentityUserRole() {  UserId=user.Id, RoleId= Roles.GetAllRoles(). })

                var result = await UserManager.CreateAsync(user, vm.Password);
                if (result.Succeeded)
                {

                    var account = new AccountController();
                    account.UserManager.AddToRole(user.Id, "Coach");

                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Coach", new { id = user.Id });
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(vm);
        }