Example #1
0
        public async Task <IActionResult> SubscribeUser(string Email)
        {
            ApplicationUser user = await userManager.FindByEmailAsync(Email);


            //check if this is an admin user.
            if (!User.IsInRole("superadmin") || !User.IsInRole("admin"))
            {
                RedirectToAction("Index", "Home");
            }

            if (user == null)
            {
                ViewBag.ErrorMessage = $"User cannot be found";
                return(View("NotFound"));
            }


            //protect Super admin

            if (user.Email.Contains("*****@*****.**"))
            {
                ViewBag.ErrorMessage = $"User cannot be found. --";
                return(View("NotFound"));
            }



            //build a view model to show all current manual subscriptions.
            var model = new SubscribeUserByAdminViewModel
            {
                Id                                   = user.Id,
                FirstName                            = user.FirstName,
                LastName                             = user.LastName,
                UserName                             = user.UserName,
                Email                                = user.Email,
                CanSeeComboPackage                   = user.CanSeeComboPackage,
                CanSeeElitePackage                   = user.CanSeeElitePackage,
                CanSeeUKRacingPackage                = user.CanSeeUKRacingPackage,
                ManualComboPackageAccessExpiresAt    = user.ManualComboPackageAccessExpiresAt,
                ManualElitePackageAccessExpiresAt    = user.ManualElitePackageAccessExpiresAt,
                ManualUKRacingPackageAccessExpiresAt = user.ManualUKRacingPackageAccessExpiresAt,

                BlockComboPackage    = user.BlockComboPackage,
                BlockUKRacingPackage = user.BlockUKRacingPackage,
                BlockElitePackage    = user.BlockElitePackage
            };

            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> SaveUserSubscription(SubscribeUserByAdminViewModel model)
        {
            //save user subscription.

            var user = await userManager.FindByEmailAsync(model.Email);

            //check if this is an admin user.
            if (!User.IsInRole("superadmin") || !User.IsInRole("admin"))
            {
                RedirectToAction("Index", "Home");
            }


            if (user == null)
            {
                ViewBag.Message = $"User cannot be found, Nothing updated.";
                return(View());
            }

            if (!user.EmailConfirmed)
            {
                ViewBag.Message = $"User have not confirmed their email. They should click on the confirmation link.";
                return(View());
            }


            //update user and save.

            user.CanSeeComboPackage                   = model.CanSeeComboPackage;
            user.CanSeeElitePackage                   = model.CanSeeElitePackage;
            user.CanSeeUKRacingPackage                = model.CanSeeUKRacingPackage;
            user.ManualComboPackageAccessExpiresAt    = model.ManualComboPackageAccessExpiresAt;
            user.ManualElitePackageAccessExpiresAt    = model.ManualElitePackageAccessExpiresAt;
            user.ManualUKRacingPackageAccessExpiresAt = model.ManualUKRacingPackageAccessExpiresAt;

            user.BlockElitePackage    = model.BlockElitePackage;
            user.BlockComboPackage    = model.BlockComboPackage;
            user.BlockUKRacingPackage = model.BlockUKRacingPackage;

            await userManager.UpdateAsync(user);

            ViewBag.Message = $"User Permissions have been updated.";


            return(View());
        }