Example #1
0
        public async Task <ActionResult <PartsOrder> > PlaceOrder(List <Inventory> inv)
        {
            decimal price = 0;
            var     cust  = await repo.GetCustomerByUserName(User.Identity.Name);

            PartsOrder order = new PartsOrder()
            {
                CustomerId  = cust.CustomerId,
                TimeOfOrder = DateTime.Now
            };

            foreach (var item in inv)
            {
                price += (decimal)item.Price;
            }
            order.FinalPrice = price;
            repo.AddOrder(order);
            await repo.Save();

            var orderId = await repo.GetRecentOrderByCustomerId(order.CustomerId);

            repo.AddJunction(orderId, inv);
            await repo.DeleteCartByCustomer(cust.CustomerId);

            await repo.Save();

            return(order);
        }
Example #2
0
        public async Task <ActionResult> Post(PartsOrder order)
        {
            repo.AddOrder(order);
            await repo.Save();

            return(CreatedAtRoute("GetOrderById", new { id = order.OrderId }, order));
        }
 public void AddOrder(PartsOrder order)
 {
     db.Add(Mapper.Map(order));
 }