コード例 #1
0
        public void AddCart(Snack snack, int amount)
        {
            var cartBuyItem = _context.CartBuyItens.SingleOrDefault(s => s.snack.Id == snack.Id && s.CartBuyId == Id);

            if (cartBuyItem == null)
            {
                cartBuyItem = new CartBuyItem()
                {
                    CartBuyId = Id,
                    snack     = snack,
                    Amount    = 1
                };
                _context.CartBuyItens.Add(cartBuyItem);
            }
            else
            {
                cartBuyItem.Amount++;
            }
            _context.SaveChanges();
        }
コード例 #2
0
        public void CreateRequest(Request request)
        {
            request.RequestSend = DateTime.Now;
            _context.Requests.Add(request);
            _context.SaveChanges();

            var cartBuy = _cartBuy.CartBuyItems;

            foreach (var item in cartBuy)
            {
                var requestDetail = new RequestDetail()
                {
                    Ammount   = item.Amount,
                    SnackId   = item.snack.Id,
                    RequestId = request.Id,
                    Price     = item.snack.Price
                };
                _context.RequestDetails.Add(requestDetail);
            }
            _context.SaveChanges();
        }