Beispiel #1
0
        public async Task insertItem(CartItemModel cartitem)
        {
            var dbItemList = _readOnlyRepository.Query <CartItem>(x => x.Cart.UserId == cartitem.UserId && x.Status == EnabledStatus.Enabled, y => y.ProductDetail).ToList();
            var dbCart     = _readOnlyRepository.Query <Cart>(x => x.UserId == cartitem.UserId && x.Status == EnabledStatus.Enabled).ToList();

            var CartId = dbCart[0].Id;

            foreach (var item in dbItemList)
            {
                if (item.ProductDetailsId == cartitem.ProductDetail.Id)
                {
                    if ((item.Quantity + cartitem.Quantity) > item.ProductDetail.Availability)
                    {
                        _repository.Update(new CartItem()
                        {
                            CartID           = CartId,
                            ProductDetailsId = cartitem.ProductDetail.Id,
                            Quantity         = item.ProductDetail.Availability,
                            UnitPrice        = cartitem.UnitPrice
                        });
                        await _repository.SaveChangesAsync();

                        return;
                    }
                    else
                    {
                        _repository.Update(new CartItem()
                        {
                            CartID           = CartId,
                            ProductDetailsId = cartitem.ProductDetail.Id,
                            Quantity         = cartitem.Quantity + item.Quantity,
                            UnitPrice        = cartitem.UnitPrice
                        });
                        await _repository.SaveChangesAsync();

                        return;
                    }
                }
            }

            _repository.Add(new CartItem()
            {
                CartID           = CartId,
                ProductDetailsId = cartitem.ProductDetail.Id,
                Quantity         = cartitem.Quantity,
                UnitPrice        = cartitem.UnitPrice
            });
            await _repository.SaveChangesAsync();
        }
Beispiel #2
0
        public async Task updateQty(CartItemModel cartitem)
        {
            var query = _readOnlyRepository.Query <Cart>(x => x.UserId == cartitem.UserId && x.Status == EnabledStatus.Enabled)
                        .ProjectTo <CartModel>(_mapper.ConfigurationProvider);

            var result = await _readOnlyRepository.SingleAsync(query);

            var CartId = result.Id;

            var entity = await _repository.FirstAsync <CartItem>(x => x.ProductDetailsId == cartitem.ProductDetail.Id && x.CartID == CartId);

            entity.Quantity = cartitem.Quantity;

            _repository.Update(entity);

            await _repository.SaveChangesAsync();
        }