Exemple #1
0
        public async Task <IActionResult> OrderProcessed(int cartId)
        {
            var user = await _userManager.GetUserAsync(User);

            var lineItems = await _context.GetLineItems(cartId);

            Cart newCart = new Cart
            {
                UserID = user.Id
            };

            // creates a new cart for the user
            await _cart.CreateCart(newCart);

            // fulfills the old cart
            var cart = await _cart.GetCart(cartId);

            cart.OrderFulfilled = true;
            await _cart.UpdateCart(cart);

            // gets the total for the cart
            decimal cartTotal = lineItems.Sum(li => li.Product.SuggestedDonation * (int)li.Quantity);

            // sends an email to confirm the order
            await _email.SendEmailAsync(user.Email, "Order Confirmation", CreateEmailString(lineItems, cartTotal));

            return(View());
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("ID,ApplicationUserID")] Cart cart)
        {
            if (ModelState.IsValid)
            {
                await _context.CreateCart(cart);

                return(RedirectToAction("Index", "Products"));
            }

            return(View(cart));
        }
Exemple #3
0
        public IHttpActionResult CreateCart([FromBody] CartModel cart)
        {
            //check if the cart exist, if so don't create cart?
            //
            var list = _Cart.CreateCart(cart);

            if (list)
            {
                return(Ok());
            }
            return(BadRequest());
        }
        /// <summary>
        /// Post the users order information on the page, and send them a receipt with said information
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnPost()
        {
            Order.OrderNumber = $"{Guid.NewGuid().ToString()}{Order.Id}";
            Cart = await _cart.GetCart(User.Identity.Name);

            string subject = $"Receipt of purchase from SuperPets for {Order.FirstName}";

            Order.Date = DateTime.Now;
            string htmlMessage = $"<h1>Your Order {Order.Date}!</h1><br><ul><li>{Order.OrderNumber}</li></ul><ul>";

            foreach (var item in Cart.CartItems)
            {
                htmlMessage += $"<li><h2>Name: {item.Product.Name}</h2>" +
                               $"<h2>Quantity: {item.Quantity}</h2>" +
                               $"<h2>Price: {item.Quantity * item.Product.Price}</h2></li>";
            }
            htmlMessage += $"<li>Total: {Cart.Price}</ul><br><ul><li>Shipping Address: {Order.Address}</li><li>City: {Order.City}</li><li>State: {Order.State}</li><li>ZipCode: {Order.ZipCode}</li></ul>";
            string card = "Card:";

            card      += Name;
            card      += ":Number";
            Order.Cart = Cart;
            await _order.CreateOrder(Order);

            string Expiration = "0221";
            string CVC        = "012";

            if (Name == "My Credit Card")
            {
                CVC = "1234";
            }

            var payment = await _payment.Run(Order.UserEmail, "370000000000002", Expiration, CVC);

            if (payment == "Failed")
            {
                Payment = true;
                return(Page());
            }
            await _sender.SendEmailAsync(Order.UserEmail, subject, htmlMessage);

            Cart.Date = DateTime.Now;
            Cart cart = new Cart()
            {
                UserEmail = User.Identity.Name,

                Date = DateTime.Now
            };
            await _cart.CreateCart(cart);

            return(new RedirectToPageResult($"/Categories/Receipt"));
        }
Exemple #5
0
        public async Task <IHttpActionResult> UpdateBook([FromBody] BookModel book)
        {
            bool isQuantityChanged = false;
            var  list = _Book.UpdateBook(book, ref isQuantityChanged);

            if (isQuantityChanged && _Book.IsBookInWaitlist(book.BookID))
            {
                var userID = _Book.GetUserInWaitlist(book.BookID);

                CartXBookModel cartXBookModel = new CartXBookModel();
                cartXBookModel.BookID   = book.BookID;
                cartXBookModel.Quantity = 1;

                CartModel cart = _Cart.GetCartByUserID(userID);
                if (cart != null)
                {
                    _Book.AddBookToCart(cart.CartID, cartXBookModel);
                }
                else
                {
                    List <CartXBookModel> cartXBookModelList = new List <CartXBookModel>();
                    cartXBookModelList.Add(cartXBookModel);
                    _Cart.CreateCart(new CartModel
                    {
                        UserID       = userID,
                        CartID       = new Guid(),
                        CreatedDate  = DateTime.Now,
                        ModifiedDate = DateTime.Now,
                        BookList     = cartXBookModelList
                    });
                }

                var currentUser = await _UserManager.FindByIdAsync(userID.ToString());

                var user = _Account.GetUserInfo(currentUser);
                OutWaitlistEmail(user, book);
            }

            if (list)
            {
                return(Ok());
            }
            return(BadRequest());
        }
Exemple #6
0
        public async Task <IActionResult> Register(RegisterAccount ra)
        {
            if (ModelState.IsValid)
            {
                CheckUserRolesExist();

                ApplicationUser newUser = new ApplicationUser()
                {
                    UserName        = ra.Email,
                    FirstName       = ra.FirstName,
                    LastName        = ra.LastName,
                    Email           = ra.Email,
                    AccountCreation = ra.AccountCreation,
                    Address         = ra.Address,
                    Birthday        = ra.Birthday,
                    LovesCats       = ra.LovesCats
                };

                var result = await _userManager.CreateAsync(newUser, ra.Password);

                if (result.Succeeded)
                {// Custom Claim type for full name
                    Claim fullNameClaim = new Claim("FullName", $"{newUser.FirstName} {newUser.LastName}");

                    // Custom claim type for loves cats
                    Claim lovesCatsClaim = new Claim("LovesCats", newUser.LovesCats.ToString().ToLower());

                    // claim type for birthday
                    Claim birthdayClaim = new Claim(
                        ClaimTypes.DateOfBirth,
                        new DateTime(newUser.Birthday.Year, newUser.Birthday.Month, newUser.Birthday.Day).ToString("u"), ClaimValueTypes.DateTime);

                    // claim type for email
                    Claim emailClaim = new Claim(ClaimTypes.Email, newUser.Email, ClaimValueTypes.Email);

                    // claim for  type address
                    Claim addressClaim = new Claim(ClaimTypes.StreetAddress, newUser.Address);

                    List <Claim> myclaims = new List <Claim>()
                    {
                        fullNameClaim,
                        birthdayClaim,
                        emailClaim,
                        addressClaim,
                        lovesCatsClaim
                    };

                    //adds the claims
                    await _userManager.AddClaimsAsync(newUser, myclaims);

                    // create a cart for the user
                    var cart = new Cart
                    {
                        User = newUser
                    };


                    // make admins if emails are these
                    if (ra.Email.ToLower() == "*****@*****.**" || ra.Email.ToLower() == "*****@*****.**" || ra.Email.ToLower() == "*****@*****.**" || ra.Email.ToLower() == "*****@*****.**")
                    {
                        await _userManager.AddToRoleAsync(newUser, UserRoles.Admin);
                    }

                    // send user an email confirmation that registration was successful
                    await _email.SendEmailAsync(newUser.Email, "Thank you for logging in", "<p> Hello!!! <strong>I am Happy!! </strong> </p>");

                    await _userManager.AddToRoleAsync(newUser, UserRoles.Member);

                    await _context.CreateCart(cart);

                    await _signInManager.SignInAsync(newUser, isPersistent : false);
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
Exemple #7
0
        /// <summary>
        /// On post Add the product to cart
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnPost()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(new RedirectToPageResult("/Account/Login"));
            }

            var cart = await _cart.GetCart(user.Email);


            if (cart == null)
            {
                cart = new Cart()
                {
                    Date      = DateTime.Now,
                    UserEmail = User.Identity.Name
                };

                await _cart.CreateCart(cart);
            }

            if (Quantity > Product.Quantity || Quantity <= 0)
            {
                IsAvailable = true;
                return(Page());
            }

            if (Quantity <= Product.Quantity && Quantity > 0)
            {
                if (cart.CartItems != null)
                {
                    foreach (var item in cart.CartItems)
                    {
                        if (item.ProductId == Product.Id)
                        {
                            var productExist = await _product.GetProduct(Product.Id);

                            productExist.Quantity = productExist.Quantity - Quantity;
                            _product.UpdateProduct(productExist).Wait();
                            var duplicateCart = await _cartItem.GetCartItem(Product.Id, cart.Id);

                            duplicateCart.Quantity = duplicateCart.Quantity + Quantity;
                            _cartItem.UpdateCartItem(duplicateCart).Wait();
                            cart.Quantity = cart.Quantity + Quantity;
                            cart.Price   += Product.Price * Quantity;
                            _cart.UpdateCart(cart).Wait();
                            return(Page());
                        }
                    }
                }
                await _cartItem.AddProductToCart(Product, cart, Quantity);

                Product.Quantity = Product.Quantity - Quantity;

                await _product.UpdateProduct(Product);
            }

            return(Page());
        }
        public async Task <IActionResult> Register(RegisterViewModel rvm)
        {
            if (ModelState.IsValid)
            {   //setting values to input from user
                ApplicationUser user = new ApplicationUser()
                {
                    UserName         = rvm.Email,
                    Email            = rvm.Email,
                    FirstName        = rvm.FirstName,
                    LastName         = rvm.LastName,
                    Birthdate        = rvm.Birthdate,
                    StreetAddress    = rvm.StreetAddress,
                    City             = rvm.City,
                    State            = rvm.State,
                    Zip              = rvm.Zip,
                    SpayedOrNeutered = rvm.SpayedOrNeutered
                };

                //creates passsword if password is in valid format
                var result = await _userManager.CreateAsync(user, rvm.Password);

                //creat a number of different claims
                if (result.Succeeded)
                {
                    await _cart.CreateCart(user);

                    Claim fullNameClaim = new Claim("FullName", $"{user.FirstName} {user.LastName}");

                    Claim spayOrNeuter = new Claim("SpayNeuter", $"{ user.SpayedOrNeutered }");

                    Claim birthdateClaim = new Claim(ClaimTypes.DateOfBirth, new DateTime(user.Birthdate.Year, user.Birthdate.Month, user.Birthdate.Day).ToString("u"),
                                                     ClaimValueTypes.DateTime);

                    Claim emailClaim = new Claim(ClaimTypes.Email, user.Email, ClaimValueTypes.Email);

                    //list to hold the claims
                    List <Claim> claims = new List <Claim> {
                        fullNameClaim, birthdateClaim, emailClaim, spayOrNeuter
                    };

                    //returns list of claims to user manager
                    await _userManager.AddClaimsAsync(user, claims);

                    //assign user to admin role if they qualify or member role otherwise
                    if (user.Email == "*****@*****.**" || user.Email == "*****@*****.**")
                    {
                        await _userManager.AddToRoleAsync(user, ApplicationRoles.Admin);
                    }
                    else
                    {
                        await _userManager.AddToRoleAsync(user, ApplicationRoles.Member);
                    }

                    //sends user to home page after sign in
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    //send user confirmation email
                    await RegistrationEmail(user);

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