Esempio n. 1
0
        public void CreateOrder(CartBoughtViewModel info)
        {
            var cart = (from c in _db.Carts                     //First we get the users cart
                        where c.UserId == info.UserId
                        select c).ToList();
            var theOrder = new List <Order>();                  //Create a List of Orders

            for (int i = 0; i < cart.Count(); i++)
            {
                var thebook = (from b in _db.Books              //For each cart item which is a book Id and quantity i get the info about the book
                               where b.Id == cart[i].BookId
                               select b).FirstOrDefault();
                theOrder.Add(new Order {                        //The reasons why Order is so large is to know where to ship and also to store the information about the book
                    UserId   = info.UserId,                     //So you would always be able to see order history even though we would delete the book
                    Title    = thebook.Title,                   //Instead of just linking bookId which would be null if we would delete the book from the database
                    Author   = thebook.Author,
                    Image    = thebook.Image,
                    Price    = thebook.Price,
                    Quantity = cart[i].Quantity,
                    FullName = info.FullName,
                    Address  = info.ShippingAddress,
                    Country  = info.Country,
                    City     = info.City,
                    PostCode = info.PostCode,
                    State    = info.State
                });
            }

            _db.AddRange(theOrder);
            _db.SaveChanges();
            clearCart(info.UserId);
        }
Esempio n. 2
0
        public IActionResult CartBought(CartBoughtViewModel info)
        {
            _cartService.CreateOrder(info);

            return(RedirectToAction("ThankYou", new { email = info.Email }));
        }
Esempio n. 3
0
 public void CreateOrder(CartBoughtViewModel info)
 {
     _cartRepo.CreateOrder(info);
 }