public async Task <IActionResult> Buy(Resources.Bought bought)
        {
            UserMDB user = _sportsShopDBContext.GetUser(bought.UserId);
            IEnumerable <CartModel> products = bought.Articles;

            foreach (var cart in products)
            {
                ProductMDB product = _sportsShopDBContext.GetProduct(cart.prodId);
                product.UnDisp = product.UnDisp - cart.quantity;
                _sportsShopDBContext.UpdateProduct(product.Id, product);

                AddToCart cartAdd = _graphContext
                                    .GetRelations <AddToCart>(user, product)
                                    .Where(c => c.Status == AddToCart.CartStatus.InCart)
                                    .FirstOrDefault();

                bool itemInCart = cartAdd != null;
                if (itemInCart && cartAdd.Status == AddToCart.CartStatus.InCart)
                {
                    cartAdd.Date   = System.DateTime.Now;
                    cartAdd.Status = AddToCart.CartStatus.Bought;
                }

                if (cartAdd != null)
                {
                    for (int i = 0; i < cartAdd.Quantity; i++)
                    {
                        _graphContext.CreateRelation(user, new Models.Bought(), product);
                    }
                }
                cartAdd.Quantity = 0;
                _graphContext.UpdateRelation(user, cartAdd, product);
            }
            return(Ok(_graphContext.GetRelatives <Models.Bought>(user)));
        }
Esempio n. 2
0
        public IEnumerable <Resources.CartModel> GetCarToUser(string id)
        {
            UserMDB user = _sportsShopDBContext.GetUser(id);

            //var cart = _sportsShopDBContext.GetUser(id).Cart;
            List <Resources.CartModel>             carts = new List <Resources.CartModel>();
            IEnumerable <RelatedItem <AddToCart> > cart  = _graphContext
                                                           .GetRelatives <AddToCart>(user)
                                                           .Where(p => p.Relation.Status == AddToCart.CartStatus.InCart);

            foreach (var c in cart)
            {
                Resources.CartModel cm = new Resources.CartModel();
                var prodInfo           = _sportsShopDBContext.GetProduct(c.Node.Id);
                cm.image    = prodInfo.Imagen;
                cm.Name     = prodInfo.Name;
                cm.price    = prodInfo.Precio;
                cm.prodId   = c.Node.Id;
                cm.quantity = c.Relation.Quantity;
                carts.Add(cm);
            }

            return(carts);
        }
Esempio n. 3
0
        public async Task <IActionResult> SearchClientHistory(string id)
        {
            var user = _sportsShopDBContext.GetUser(id);
            List <Resources.Article> articlesBought =
                new List <Resources.Article>();
            var articles = _graphContext.GetRelatives <Bought>(user);

            var products = _sportsShopDBContext.GetProducts();

            foreach (var item in products)
            {
                foreach (var article in articles)
                {
                    if (article.Node.Id.Equals(item.Id))
                    {
                        var add =
                            new Resources.Article(article.Relation.Date.ToLongDateString(), item);
                        articlesBought.Add(add);
                    }
                }
            }

            return(Ok(articlesBought));
        }