Пример #1
0
        public async Task CreateOrder(OrderDetailModel orderDetailModel)
        {
            foreach (var item in orderDetailModel.OrderModels)
            {
                var userItem = new UserItem
                {
                    UserId = orderDetailModel.UserId,
                    ItemId = item.ItemId,
                    Amount = item.Amount
                };

                var userItemEntity = _context.UserItems
                                     .Where(x => x.UserId == userItem.UserId &&
                                            x.ItemId == userItem.ItemId)
                                     .FirstOrDefault();

                if (userItemEntity == null)
                {
                    _context.UserItems.Add(userItem);
                }
                else
                {
                    userItemEntity.Amount = userItem.Amount;
                }
            }

            await _context.SaveChangesAsync();
        }
Пример #2
0
        public async Task <int> GetMasterData(string foodyUrl)
        {
            var menuModels = await GetMenuModels(foodyUrl);

            foreach (var item in menuModels)
            {
                _foodyContext.Categories.Add(new Category
                {
                    Name  = item.CategoryName,
                    Items = item.MenuItems.Select(x => new Entities.Item
                    {
                        Name   = x.Name,
                        Photos = x.Photos,
                        Price  = x.Price
                    }).ToList()
                });
            }

            var result = await _foodyContext.SaveChangesAsync();

            return(result);
        }