Esempio n. 1
0
        public OrderSplitedDto SeparatePeriodFromDishes(InputOrderDto inputOrderDto)
        {
            var           orderInfoDto    = new OrderSplitedDto();
            List <string> stringParts     = inputOrderDto.ClientOrderInput.Split(',').ToList();
            var           dayPeriodString = stringParts.FirstOrDefault().ToLower();

            Enum.TryParse(dayPeriodString, out DayPeriodEnum dayPeriodEnum);

            if (dayPeriodEnum != DayPeriodEnum.morning && dayPeriodEnum != DayPeriodEnum.night)
            {
                return(null);
            }

            orderInfoDto.DayPeriod = dayPeriodEnum;
            stringParts.RemoveAt(0);

            if (stringParts != null && stringParts.Count() != 0 && stringParts.FirstOrDefault().Trim() != "")
            {
                orderInfoDto.DishesList = stringParts;
            }
            else
            {
                return(null);
            }

            return(orderInfoDto);
        }
Esempio n. 2
0
        public void TestSplitDishesWithSuccess()
        {
            using (var context = _serviceProvider.GetService <RestaurantOrderContext>())
            {
                var repo    = new ClientOrderHistoryRepository(context);
                var service = new RestaurantOrderAppService(repo, _mapper);

                var inputOrderDto = new InputOrderDto();
                inputOrderDto.ClientOrderInput = "morning, 1, 2, 3, 3, 3";

                var expectedResponse   = new OrderSplitedDto();
                var expectedListDishes = new List <string>();
                expectedListDishes.Add(" 1");
                expectedListDishes.Add(" 2");
                expectedListDishes.Add(" 3");
                expectedListDishes.Add(" 3");
                expectedListDishes.Add(" 3");

                expectedResponse.DayPeriod  = DayPeriodEnum.morning;
                expectedResponse.DishesList = expectedListDishes;

                var response = service.SeparatePeriodFromDishes(inputOrderDto);

                Assert.Equal(expectedListDishes, response.DishesList);
            }
        }
Esempio n. 3
0
        public void TestSplitDishesWithError()
        {
            using (var context = _serviceProvider.GetService <RestaurantOrderContext>())
            {
                var repo    = new ClientOrderHistoryRepository(context);
                var service = new RestaurantOrderAppService(repo, _mapper);

                var inputOrderDto = new InputOrderDto();
                inputOrderDto.ClientOrderInput = "afternoon, 1, 2, 3, 3, 3";

                var response = service.SeparatePeriodFromDishes(inputOrderDto);

                Assert.Null(response);
            }
        }
Esempio n. 4
0
        public IActionResult CreateOrder([FromBody] InputOrderDto inputOrderDto)
        {
            var orderSplitedDto = _restaurantOrderAppService.SeparatePeriodFromDishes(inputOrderDto);

            if (orderSplitedDto == null)
            {
                return(BadRequest("Invalid Input"));
            }

            var clientOrderHistoryDto = _restaurantOrderAppService.CreateOrderOutput(orderSplitedDto, inputOrderDto.ClientOrderInput);

            _restaurantOrderAppService.AddOrderHistory(clientOrderHistoryDto);
            var clientOrderHistoryList   = _restaurantOrderAppService.GetAllOrderHistory();
            var orderOutPutAndHistoryDto = _restaurantOrderAppService.GenerateOrderOutputHistory(clientOrderHistoryDto.ClientOrderOutput, clientOrderHistoryList);

            return(Ok(orderOutPutAndHistoryDto));
        }