Exemplo n.º 1
0
        public override void Execute(string[] commandArgs)
        {
            string id       = commandArgs[1];
            var    item     = this.AppEngine.Supplies.FirstOrDefault(pair => pair.Key.ID == id).Key;
            var    rentDate = ToDateTime(commandArgs[2]);
            var    deadline = ToDateTime(commandArgs[3]);

            if (item == null)
            {
                throw new ArgumentNullException(string.Format("No item {0} in supplies stock.", id));
            }

            if (this.AppEngine.Supplies[item] == 0)
            {
                throw new InsufficientSuppliesException("There are not enough supplies to rent this item.");
            }

            RentsManager.AddRent(item, rentDate, deadline);
            this.AppEngine.Supplies[item]--;
        }
Exemplo n.º 2
0
        public override void Execute(string[] commandArgs)
        {
            string reportType = commandArgs[1];

            switch (reportType)
            {
            case "sales":
                DateTime startDate   = ToDateTime(commandArgs[2]);
                decimal  salesIncome = SalesManager.ReportSalesIncome(startDate);

                Console.WriteLine(string.Format("{0:F2}", salesIncome));
                break;

            case "rents":
                var overdueRents = RentsManager.ReportOverdueRents();

                Console.WriteLine(string.Join("\n", overdueRents));
                break;

            default:
                throw new ArgumentException("Invalid report type.");
            }
        }