Esempio n. 1
0
        /// <summary>
        /// Action that allows us to talk to our database
        /// and create a new product
        /// </summary>
        /// <param name="product">product being passed in</param>
        /// <returns>A statuscode of created</returns>
        public async Task <HttpStatusCode> CreateProduct(Product product)
        {
            await _context.Products.AddAsync(product);

            await _context.SaveChangesAsync();

            return(HttpStatusCode.Created);
        }
Esempio n. 2
0
        /// <summary>
        /// Action that allows for the creation of a new cart. This cart
        /// is attached given a userID so it knows what user it belongs to
        /// </summary>
        /// <param name="user">Passes in a user to get an id</param>
        /// <returns>StatusCode of Created</returns>
        public async Task <HttpStatusCode> CreateCart(ApplicationUser user)
        {
            Cart cart = new Cart
            {
                UserID = user.Id
            };
            await _context.Carts.AddAsync(cart);

            await _context.SaveChangesAsync();

            return(HttpStatusCode.Created);
        }
Esempio n. 3
0
        /// <summary>
        /// Action that allows us to create an order for our records when the
        /// user is at checkout
        /// </summary>
        /// <param name="user">ApplicationUser</param>
        /// <param name="totalPrice">Total price of the order</param>
        /// <returns>Newly created order</returns>
        public async Task <Order> CreateOrder(ApplicationUser user, decimal totalPrice)
        {
            Order newOrder = new Order
            {
                UserID     = user.Id,
                TotalPrice = totalPrice,
                OrderDate  = DateTime.Today
            };
            await _context.Orders.AddAsync(newOrder);

            await _context.SaveChangesAsync();

            var order = await _context.Orders.Where(o =>
                                                    (o.UserID == user.Id) &&
                                                    (o.IsCheckedOut != true))
                        .OrderBy(o => o.ID)
                        .FirstOrDefaultAsync();

            return(order);
        }