Exemplo n.º 1
0
        public async Task Add(string userId, string userName, string fullName, IEnumerable <MenuOrder> menuOrders)
        {
            var menu = await _cacheService.GetMenu();

            if (!string.IsNullOrEmpty(menu.Vendor.SubmitOrderTime))
            {
                DateTime parsedOrderDateTime;
                if (DateTime.TryParse(menu.Vendor.SubmitOrderTime, out parsedOrderDateTime))
                {
                    if (TimeSpan.Compare(parsedOrderDateTime.TimeOfDay, DateTime.UtcNow.TimeOfDay) <= 0)
                    {
                        throw new BusinessException($"Sorry, you were too late to submit your order for today");
                    }
                }
            }

            var menuOrderHistoryEntries =
                _mapper.Map <IEnumerable <MenuOrder>, IEnumerable <UserOrderHistoryEntry> >(menuOrders);

            var userOrderHistory = new UserOrderHistory
            {
                Id        = Guid.NewGuid(),
                OrderTime = DateTime.UtcNow,
                Entries   = menuOrderHistoryEntries
            };

            await
            _databaseRepository.AddOrder(userId, userName, menu.Vendor.Id,
                                         new DateGenerator().GenerateDateFormat(DateTime.UtcNow), userOrderHistory, fullName);

            _eventingService.SendMessage(new Message(ServicebusType.AddUserOrder,
                                                     JsonConvert.SerializeObject(userOrderHistory)));
        }