Esempio n. 1
0
        public async Task <bool> AddAsync(IList <T> entities)
        {
            try
            {
                await _dbContext.AddRangeAsync(entities);

                await _dbContext.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> AddOrder([FromBody] Models.Order order)
        {
            if (order.OrderItems.Count() == 0)
            {
                return(BadRequest(new { success = false, message = "OrderItem Is Null" }));
            }

            string access_token = await HttpContext.GetTokenAsync("access_token");

            var user = _token.GetPayloadAsync(access_token);

            var temp = order.OrderItems;

            var result = temp.GroupBy(t => t.UserId)
                         .Select(g => new Models.Order()
            {
                Address       = order.Address,
                Fullname      = order.Fullname,
                PhoneNumber   = order.PhoneNumber,
                PaymentIntent = order.PaymentIntent,
                BuyerId       = user.UserId,
                UserId        = g.Key,
                Status        = 1,
                OrderItems    = g.ToList()
            });

            await _context.AddRangeAsync(result);

            await _context.SaveChangesAsync();

            var endPoint = await _sendEndpointProvider.
                           GetSendEndpoint(new Uri("queue:" + BusConstant.AddAmountQueue));

            foreach (var item in temp)
            {
                await endPoint.Send <AddAmountMessage>(new
                {
                    BookId = item.BookId,
                    Amount = item.Amount,
                    isAdd  = true
                });
            }
            ;

            return(Ok(new { success = true, data = result }));
        }
Esempio n. 3
0
        public async Task <IList <OrderItemDto> > AddToCartAsync(int orderId, AddToCartDto model)
        {
            var addedItems = model.Items
                             .Select(i => new OrderItem
            {
                OrderId   = orderId,
                ProductId = i.ProductId,
                Quantity  = i.Quantity
            })
                             .ToList();

            await _context.AddRangeAsync(addedItems);

            await _context.SaveChangesAsync();

            return(addedItems.MapToOrderItemDtoCollection());
        }