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"));
        }
Beispiel #3
0
 public int Insert(Profit prof)
 {
     return(profRep.Insert(prof));
 }