コード例 #1
0
        public override string GetCommandResult(List <string> args, List <Product> productList, List <Campaign> campaignList, List <Order> orderList, TimeHandler timeHandler)
        {
            string result = string.Empty;

            Campaign campaign = new Campaign
            {
                Name               = args[0].ToString(),
                ProductCode        = args[1].ToString(),
                Duration           = Convert.ToInt32(args[2]),
                PMLimit            = Convert.ToInt32(args[3]),
                TargetSalesCount   = Convert.ToInt32(args[4]),
                IsActive           = true,
                IncreaseOrDecrease = Enum.DirectionOfChange.DECREASE
            };

            campaignList.Add(campaign);

            campaign.AddObserver(FindProduct(productList, args[1].ToString()));

            timeHandler.AddObserver(campaign);

            result = string.Format("Campaign created; name {0}, product {1}, duration {2},limit {3}, target sales count {4}",
                                   campaign.Name, campaign.ProductCode, campaign.Duration, campaign.PMLimit, campaign.TargetSalesCount);

            return(result);
        }
コード例 #2
0
        public override string GetCommandResult(List <string> args, List <Product> productList, List <Campaign> campaignList, List <Order> orderList, TimeHandler timeHandler)
        {
            string result = string.Empty;

            Product product = FindProduct(productList, args[0].ToString());

            if (product == null)
            {
                result = string.Format("Product {0} info; product not found ", args[0].ToString());
            }
            else
            {
                result = string.Format("Product {0} info; price {1}, stock {2}", product.Code, product.Price, product.Stock);
            }

            return(result);
        }
コード例 #3
0
 public abstract string GetCommandResult(List <string> args, List <Product> productList, List <Campaign> campaignList, List <Order> orderList, TimeHandler timeHandler);
コード例 #4
0
ファイル: CreateOrder.cs プロジェクト: alpbsra/CampaignModule
        public override string GetCommandResult(List <string> args, List <Product> productList, List <Campaign> campaignList, List <Order> orderList, TimeHandler timeHandler)
        {
            string result    = string.Empty;
            int    mQuantity = Convert.ToInt32(args[1]);

            Product prd = FindProduct(productList, args[0].ToString());

            prd.Stock -= mQuantity;

            Order order = new Order {
                ProductCode = args[0].ToString(), Quantitiy = mQuantity, TotalCost = prd.Price * mQuantity
            };

            orderList.Add(order);

            result = string.Format("Order created; product {0}, quantity {1}", order.ProductCode, order.Quantitiy);

            return(result);
        }
コード例 #5
0
        public override string GetCommandResult(List <string> args, List <Product> productList, List <Campaign> campaignList, List <Order> orderList, TimeHandler timeHandler)
        {
            string result = string.Empty;

            Product product = new Product {
                Code = args[0].ToString(), Price = Convert.ToDecimal(args[1]), RawPrice = Convert.ToDecimal(args[1]), Stock = Convert.ToInt32(args[2])
            };

            productList.Add(product);

            result = string.Format("Product created; code {0}, price {1}, stock {2}", product.Code, product.Price, product.Stock);

            return(result);
        }
コード例 #6
0
        public override string GetCommandResult(List <string> args, List <Product> productList, List <Campaign> campaignList, List <Order> orderList, TimeHandler timeHandler)
        {
            string result = string.Empty;

            Campaign campaign = campaignList.Find(x => x.Name == args[0].ToString());

            if (campaign == null)
            {
                result = string.Format("Campaign {0} info; campaign not found ", args[0].ToString());
            }
            else
            {
                int     totalSales       = orderList.Where(x => x.ProductCode == campaign.ProductCode).Sum(x => x.Quantitiy);
                decimal totalCost        = orderList.Where(x => x.ProductCode == campaign.ProductCode).Sum(x => x.TotalCost);
                decimal averageItemPrice = totalCost > 0 ? decimal.Round(totalCost / totalSales, 2) : 0;
                decimal turnover         = totalSales * averageItemPrice;

                result = string.Format("Campaign {0} info; Status {1}, Target Sales {2},Total Sales {3}, Turnover {4}, Average Item Price {5}",
                                       campaign.Name, campaign.IsActive ? "Active" : "Passive", campaign.TargetSalesCount, totalSales, turnover, averageItemPrice);
            }


            return(result);
        }