Ejemplo n.º 1
0
        private void _txtFinish_Click(object sender, EventArgs e)
        {
            var order = new OrderSale()
            {
                Date        = DateTime.Now,
                Discount    = _txtDiscountAll.ToPrice(),
                Note        = _txtNote.Text,
                Ship        = _txtShip.ToPrice(),
                Total       = _txtTotalPrice.ToPrice(),
                OrderStatus = _orderStatus,
                OrderType   = _orderType,
            };

            OrderSaleRepository.Instance.Insert(order);

            int             profit    = 0;
            List <ItemSale> itemSales = new List <ItemSale>();
            string          name      = "";

            foreach (var item in _currentListItemSaleModels)
            {
                itemSales.Add(new ItemSale()
                {
                    OrderSaleId   = order.Id,
                    ProductSaleId = item.ProductSaleId,
                    ColorId       = item.ColorId,
                    ColorName     = item.ColorName,
                    Discount      = item.Discount.ToPrice(),
                    Price         = item.SellPrice.ToPrice(),
                    ProductName   = item.ProductName,
                    Quantity      = item.Quantity,
                    SizeId        = item.SizeId,
                    SizeName      = item.SizeName,
                });
                name   += " " + item.ProductName;
                profit += (item.TotalPrice.ToPrice() - (item.InputPrice * item.Quantity));
                var productSale = ProductSaleRepository.Instance.GetById(item.ProductSaleId);
                productSale.Quantity -= item.Quantity;
                ProductSaleRepository.Instance.Update(productSale);
            }
            ItemSaleRepository.Instance.InsertAll(itemSales);
            order.Profit = profit - _txtDiscountAll.ToPrice();
            OrderSaleRepository.Instance.Update(order);
            ModelHelper.InputMoney(order.Total, name);
            Close();
        }
Ejemplo n.º 2
0
        public void AddProductToOrder(ClassLibrary.Models.OrderSale orderSale)
        {
            using var context = new Project0DBContext(_contextOptions);


            var newOrderSale = new OrderSale()
            {
                ProductId   = orderSale.ProductId,
                ProductName = orderSale.ProductName,
                Quantity    = orderSale.Quantity,
                SalePrice   = orderSale.SalePrice
            };

            context.OrderSales.Add(newOrderSale);

            context.SaveChanges();
        }