Exemplo n.º 1
0
        public IActionResult Add([FromBody] DataContracts.Requests.Order contract)
        {
            var day = calendar.GetCurrentDay();

            if (day == null)
            {
                return(BadRequest("There isn't an open day available"));
            }

            if (day.Date != DateTime.Today)
            {
                return(BadRequest($"The day {day.Date} should be closed first"));
            }

            if (contract.Id != 0)
            {
                return(BadRequest("The contract id of an order to be created must be 0"));
            }

            contract.OrderingDate = DateTime.Now;

            var wrappedOrder = ModelFromDataContract(contract);

            if (wrappedOrder.HasError)
            {
                return(BadRequest(wrappedOrder.ErrorMessage));
            }

            return(Ok((int)orderBook.Add(wrappedOrder.Model)));
        }
Exemplo n.º 2
0
        public DateTime?GetCurrentDay()
        {
            var day = calendar.GetCurrentDay();

            return(day?.Date);
        }