예제 #1
0
        public IActionResult Index(int Id)
        {
            HomePageViewModel model = new HomePageViewModel();

            payment = 0;

            var userId  = User.FindFirst(ClaimTypes.NameIdentifier).Value.ToString();
            var product = repoProduct.GetById(Id);

            repo.AddBasket(product, userId);

            var baskets  = repo.Baskets.Where(x => x.UserId == userId && x.ProductState == false);
            var products = repoProduct.Products;

            var productBasket =
                from x in products
                join y in baskets on x.Id equals y.ProductId
                select x;


            foreach (var item in productBasket)
            {
                payment += item.Price;
            }

            ViewData["payment"]    = Math.Round(payment, 2).ToString();
            ViewData["countTotal"] = productBasket.Count();
            count = productBasket.Count();

            model.Products = productBasket;
            return(View(model));
        }
예제 #2
0
        public IViewComponentResult Invoke(int Id, string userId)
        {
            payment = 0;

            var product = repoProduct.GetById(Id);

            repo.AddBasket(product, userId);

            var baskets  = repo.Baskets;
            var products = repoProduct.Products;

            var productBasket =
                from x in products
                join y in baskets on x.Id equals y.ProductId
                select x;


            foreach (var item in productBasket)
            {
                payment += item.Price;
            }

            ViewData["payment"]    = Math.Round(payment, 2).ToString();
            ViewData["countTotal"] = productBasket.Count();
            count = productBasket.Count();
            return(View(productBasket));
        }
예제 #3
0
        public async Task <IActionResult> Register(RegisterViewModel rvm)
        {
            //if (the forms are filled correctly)
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName       = rvm.Email,
                    Email          = rvm.Email,
                    FirstName      = rvm.FirstName,
                    LastName       = rvm.LastName,
                    Birthday       = rvm.Birthday,
                    FavoriteAnimal = rvm.FavoriteAnimal
                };
                //inserts user data into userdb
                var result = await _userManager.CreateAsync(user, rvm.Password);

                //after user data successfully placed in db
                if (result.Succeeded)
                {
                    //create a list of claims called claims
                    List <Claim> claims = new List <Claim>();


                    // create new claims
                    Claim nameClaim   = new Claim("FullName", $"{user.FirstName} {user.LastName}");
                    Claim emailClaim  = new Claim(ClaimTypes.Email, user.Email, ClaimValueTypes.Email);
                    Claim animalClaim = new Claim("FavAnimal", $"{user.FavoriteAnimal}");


                    //add claims to claims list
                    claims.Add(nameClaim);
                    claims.Add(emailClaim);
                    claims.Add(animalClaim);

                    await _userManager.AddClaimsAsync(user, claims);

                    // Instantiates a new basket
                    Basket basket = new Basket();
                    //Sets basket's userID as id of user
                    basket.UserID = user.Id;
                    //Dependency Injection to IBasket
                    //There we will add the basket to the BasketTable
                    //AddToBasket and AddBasket are different
                    _context.AddBasket(basket);

                    if (user.Email == "*****@*****.**")
                    {
                        await _userManager.AddToRoleAsync(user, ApplicationRoles.Admin);

                        await _userManager.AddToRoleAsync(user, ApplicationRoles.Member);

                        await _signInManager.SignInAsync(user, false);

                        return(RedirectToAction("Index", "Admin"));
                    }
                    await _signInManager.SignInAsync(user, false);

                    await _emailSender.SendEmailAsync(user.Email, "Welcome", "<p> You have successfully registered </p>");

                    await _userManager.AddToRoleAsync(user, ApplicationRoles.Member);

                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(rvm));
        }