//post users and create order details
        public async Task <OrderDetailsAC> AddOrderDetails(OrderDetailsAC detailsAC)
        {
            Restaurant restaurants = await _dataRepository.FirstAsync <Restaurant>(x => x.ID == detailsAC.RestaurantID);

            User user = await _dataRepository.Where <User>(u => u.Id == detailsAC.UserID).FirstAsync();

            ICollection <DishesOrdered> orderedDishes = detailsAC.DishesOrdered;
            var listOfDishes = _dataRepository.GetAll <Dishes>();

            foreach (var item in orderedDishes)
            {
                item.Dishes = await listOfDishes.Where(k => k.ID == item.Dishes.ID).FirstAsync();
            }
            OrderDetails orders = new OrderDetails();

            _mapper.Map(detailsAC, user);
            _mapper.Map(detailsAC, restaurants);

            orders.User       = user;
            orders.Restaurant = restaurants;

            await _dataRepository.AddAsync <OrderDetails>(orders);

            await _dataRepository.AddRangeAsync <DishesOrdered>(orderedDishes);

            await _dataRepository.SaveChangesAsync();

            detailsAC.DishesOrdered = orderedDishes;
            return(detailsAC);
        }
예제 #2
0
        public async Task AddOrderDetails_PostUsersAndCreateOrderDetails()
        {
            List <User> users = new List <User>
            {
                new User
                {
                    Id       = "dcbe1262-4be8-493a-8821-f4d52778d878",
                    UserName = "******"
                }
            };

            List <Dishes> dishes = new List <Dishes>
            {
                new Dishes
                {
                    ID         = 1,
                    DishesName = "Burger",
                    Costs      = 250
                }
            };

            OrderDetailsAC orderDetailsACs = new OrderDetailsAC
            {
                RestaurantID  = 1,
                UserID        = "dcbe1262-4be8-493a-8821-f4d52778d878",
                UserName      = "******",
                DishesOrdered = new List <DishesOrdered>
                {
                    new DishesOrdered
                    {
                        ID         = 1,
                        ItemsCount = 4,
                        Dishes     = new Dishes
                        {
                            ID         = 1,
                            DishesName = "burger",
                            Costs      = 200
                        }
                    }
                }
            };

            _dataRepository.Setup(s => s.FirstAsync(It.IsAny <Expression <Func <Restaurant, bool> > >()));
            _dataRepository.Setup(s => s.Where(It.IsAny <Expression <Func <User, bool> > >())).Returns(users.AsQueryable().BuildMock().Object);
            _dataRepository.Setup(s => s.GetAll <Dishes>()).Returns(dishes.AsQueryable().BuildMock().Object);
            _dataRepository.Setup(s => s.AddAsync(It.IsAny <Expression <Func <OrderDetails, bool> > >()));
            _dataRepository.Setup(s => s.AddRangeAsync(It.IsAny <IEnumerable <OrderDetails> >()));
            _dataRepository.Setup(s => s.SaveChangesAsync());

            await _unitOfWorkRepository.Restaurant.AddOrderDetails(orderDetailsACs);

            _dataRepository.Verify(v => v.AddAsync(It.IsAny <OrderDetails>()), Times.Once);
            _dataRepository.Verify(v => v.AddRangeAsync(It.IsAny <IEnumerable <DishesOrdered> >()));
            _dataRepository.Verify(v => v.SaveChangesAsync());
        }
예제 #3
0
        public async Task <ActionResult> AddOrderDetails(OrderDetailsAC orderDetails)
        {
            var o = await unitOfWork.Restaurant.AddOrderDetails(orderDetails);

            return(Ok(o));
        }