Beispiel #1
0
        public void Buy(Clothes clothes, int quantity)
        {
            var clothe = Clothes.FirstOrDefault(x => x.Type == clothes.Type && x.Size == clothes.Size && x.Color == clothes.Color);

            if (clothe != null)
            {
                clothe.Quantity += quantity;
                Money           -= clothes.BuyPrice * quantity;
            }
            else
            {
                clothes.Quantity = quantity;
                Clothes.Add(clothes);
                Money -= clothes.BuyPrice * quantity;
            }
        }
Beispiel #2
0
        public int Sell(Clothes clothes, int quantity)
        {
            var clothe = Clothes.FirstOrDefault(x => x.Type == clothes.Type && x.Size == clothes.Size && x.Color == clothes.Color);

            if (clothe != null)
            {
                if (clothe.Quantity >= quantity)
                {
                    clothe.Quantity -= quantity;
                    Money           += clothes.SellPrice * quantity;
                    return(0);
                }
                else
                {
                    return(1);
                }
            }
            return(2);
        }
Beispiel #3
0
        private void ExecuteSellingOrderAction(int colorId, int sizeId, int quantity, Customer selectedCustomer, Clothes selectedClothes, Rate rate)
        {
            int    customerId  = selectedCustomer.Id;
            int    clothesId   = selectedClothes.Id;
            string clothesName = selectedClothes.Name;

            Console.WriteLine("# Create selling order: ");
            var newOrder = new SellingOrder
            {
                SupplierId = selectedClothes.SupplierId,
                CustomerId = customerId,
                Status     = OrderStatus.New,
                OrderDate  = DateTime.Now
            };

            Console.WriteLine($"+ New selling order - Id: {newOrder.Id}, Order date: {newOrder.OrderDate}, CustomerId Id: {customerId}, CustomerId Name: {selectedCustomer.Name}");

            var tempSellingOrders      = _dataProvider.sellingOrders.GetAll();
            var tempSellingOrderDetail = _dataProvider.sellingOrderDetails.GetAll();

            Console.WriteLine("+ Save temp order");
            TransactionProvider.ExecuteOperationInTransaction(() =>
            {
                int newOrderId = tempSellingOrders.Add <SellingOrder>(newOrder);

                var sellingRateByClothes = _dataProvider.clothesRates.GetBy(x => x.ClothesId == selectedClothes.Id && x.RateId == rate.Id).FirstOrDefault();
                if (sellingRateByClothes == null)
                {
                    throw new Exception("Selling rate does not exist for clothes");
                }

                Console.WriteLine("# Create selling order detail");

                var newOrderDetail = new SellingOrderDetail
                {
                    OrderId    = newOrderId,
                    ClothesId  = clothesId,
                    ColorId    = colorId,
                    SizeId     = sizeId,
                    Quantity   = quantity,
                    TotalPrice = quantity * sellingRateByClothes.Price
                };
                tempSellingOrderDetail.Add(newOrderDetail);

                Console.WriteLine($"+ New selling order detail - OrderId: {newOrderDetail.OrderId}, Clothes Id: {clothesId}, Clothes Name: {clothesName}, Quantity: {newOrderDetail.Quantity}, TotalPrice: {newOrderDetail.TotalPrice}");
            });

            Console.WriteLine("+ Save actual order");
            _dataProvider.sellingOrders       = tempSellingOrders;
            _dataProvider.sellingOrderDetails = tempSellingOrderDetail;

            Console.WriteLine("+ Approve order and add to stock");
        }