public IHttpActionResult Post(int id)
        {
            TempOrderProduct temporderProduct = temporderProductRepository.Get(id);
            var       pid    = temporderProduct.ProductID;
            TempOrder torder = temporderrepo.Get(Convert.ToInt32(temporderProductRepository.Get(id).TempOrderId));

            temporderProductRepository.Delete(temporderProductRepository.Get(id).TempOrderProductID);
            temporderrepo.Delete(Convert.ToInt32(torder.TempOrderId));


            Order order = new Order();

            order.date          = DateTime.Now;
            order.PayMentMethod = torder.PayMentMethod;
            order.Quantity      = torder.Quantity;
            order.Size          = torder.Size;
            order.totalAmount   = torder.totalAmount;
            orderrepo.Insert(order);


            OrderProduct orderProduct = new OrderProduct();

            orderProduct.ProductHistoryId = producthis.GetByProductNameCategory(productrepo.Get(Convert.ToInt32(pid)).Product_name, productrepo.Get(Convert.ToInt32(pid)).MainCategoryId).ProductHistoryId;
            orderProduct.CustomerID       = temporderProduct.CustomerID;
            orderProduct.OrderID          = order.OrderID;
            productorderrepo.Insert(orderProduct);

            Profit profit = new Profit();

            ProductHistory phis = producthis.Get(orderProduct.ProductHistoryId);

            profit.OrderProductId = orderProduct.OrderProductId;
            if (phis.Sale != null)
            {
                var p  = (double)phis.UnitPrice;
                var v  = Convert.ToDouble(phis.Sale.Amount) / 100;
                var c1 = (p - (p * v));
                profit.ProfitAmount = ((decimal)c1 - phis.Cost) * order.Quantity;
            }
            else
            {
                profit.ProfitAmount = (phis.UnitPrice - phis.Cost) * order.Quantity;
            }


            profitrepo.Insert(profit);

            return(Ok("success"));
        }
        public ActionResult Confirmorder(int id)
        {
            TempOrderProduct temporderProduct = temporderProductRepository.Get(id);
            TempOrder        torder           = temporderrepo.Get(temporderProductRepository.Get(id).OrderID);

            temporderProductRepository.Delete(temporderProductRepository.Get(id).ProductOrderID);
            temporderrepo.Delete(temporderProduct.OrderID);


            Order order = new Order();

            order.date          = DateTime.Now;
            order.PayMentMethod = torder.PayMentMethod;
            order.Quantity      = torder.Quantity;
            order.Size          = torder.Size;
            order.totalAmount   = torder.totalAmount;
            orderrepo.Insert(order);


            OrderProduct orderProduct = new OrderProduct();

            orderProduct.ProductID  = temporderProduct.ProductID;
            orderProduct.CustomerID = temporderProduct.CustomerID;
            orderProduct.OrderID    = order.OrderID;
            productorderrepo.Insert(orderProduct);

            Profit profit = new Profit();

            ProductHistory phis = producthis.Get(orderProduct.ProductID);

            profit.ProductOrderID = orderProduct.ProductOrderID;
            if (phis.Sale != null)
            {
                var p  = (double)phis.UnitPrice;
                var v  = Convert.ToDouble(phis.Sale.Amount) / 100;
                var c1 = (p - (p * v));
                profit.ProfitAmount = ((decimal)c1 - phis.Cost) * order.Quantity;
            }
            else
            {
                profit.ProfitAmount = (phis.UnitPrice - phis.Cost) * order.Quantity;
            }


            profitrepo.Insert(profit);

            return(Json("success"));
        }
Exemplo n.º 3
0
        public void AddItemToCart(int id, string username)
        {
            shoppingCartID = GetCartID();
            ProductOrder   = new ProductOrder();
            var item = _itemRepository.GetById(id);

            if (item != null)
            {
                //FoodOrder
                var foodItem =
                    _productOrderRepository.Find(x => x.cart_id == shoppingCartID && x.item_id == item.ItemCode).FirstOrDefault();
                var cartItem =
                    _cartItemRepository.Find(x => x.cartId == shoppingCartID && x.ItemdId == item.ItemCode).FirstOrDefault();
                if (cartItem == null)
                {
                    var cart = _cartRepository.GetById(shoppingCartID);
                    if (cart == null)
                    {
                        _cartRepository.Insert(model: new Cart()
                        {
                            CartID       = shoppingCartID,
                            date_created = DateTime.Now
                        });
                        //dataContext.SaveChanges();
                    }

                    _cartItemRepository.Insert(model: new CartItem()
                    {
                        Id        = Guid.NewGuid().ToString(),
                        cartId    = shoppingCartID,
                        ItemdId   = item.ItemCode,
                        quantity  = 1,
                        price     = item.Price,
                        UserEmail = username
                    }
                                               );
                    //food.item_id = cartItem.item_id;
                    //food.cart_id = cartItem.cart_id;
                    //food.quantity = cartItem.quantity;
                    //food.UserEmail = cartItem.UserEmail;
                    //dataContext.FoodOrders.Add(food);



                    _productOrderRepository.Insert(model: new ProductOrder()
                    {
                        cart_item_id = Guid.NewGuid().ToString(),
                        cart_id      = shoppingCartID,
                        item_id      = item.ItemCode,
                        quantity     = 1,
                        price        = item.Price,
                        ItemName     = item.Name,
                        UserEmail    = username,
                        Picture      = item.Picture,
                        OrderDate    = DateTime.Now.Date.ToString(),
                        OrderStatus  = "Not Cheked Out"
                    });
                }
                else
                {
                    cartItem.quantity++;
                    foodItem.quantity++;
                }
                //dataContext.SaveChanges();
            }
        }