Exemplo n.º 1
0
        public IActionResult CloseDay([FromBody] DataContracts.Requests.DaySlip contract)
        {
            var openedOrders = orderBook.GetAll();

            if (openedOrders.Any())
            {
                return(BadRequest("OpenedOrdersPending"));
            }

            var openedBills = billBook.GetAll();

            if (openedBills.Any())
            {
                return(BadRequest("OpenedBillsPending"));
            }

            var day = calendar.Get(contract.Day);

            if (day == null)
            {
                return(BadRequest("DayNotOpened"));
            }

            if (day.Closed)
            {
                return(BadRequest("DayAlreadyClosed"));
            }

            var daySlip = contract.ToDaySlip(day);

            daySlipBook.Add(daySlip);
            day.Close();
            calendar.Update(day);

            return(Ok());
        }