public async Task <IHttpActionResult> GetOwnShopProducts() { CurrentIdentity identity = getIdentity(); Shop shop = await db.Shops.FirstOrDefaultAsync(p => p.UserId == identity.userId); if (shop == null) { return(ResponseMessage(getHttpResponse(HttpStatusCode.NotFound))); } ShopProducts shopOut = new ShopProducts(); shopOut.Id = shop.Id; shopOut.UserId = shop.UserId; shopOut.Title = shop.Title; shopOut.Description = shop.Description; shopOut.DescriptionFull = shop.DescriptionFull; shopOut.Views = shop.Views; shopOut.IsActive = shop.IsActive; shopOut.CreatedAt = shop.CreatedAt; shopOut.UpdatedAt = shop.UpdatedAt; shopOut.Products = new List <ProductOut>(); IList <Product> productsInShop = new List <Product>(); productsInShop = await db.Products.Where(p => p.ShopId == shop.Id).ToListAsync(); foreach (var product in productsInShop) { shopOut.Products.Add(await GetProductsForShop(product.Id)); } return(Ok(shopOut)); }
public async Task <IHttpActionResult> GetShopProducts(long id) { Shop shop = await db.Shops.FindAsync(id); if (shop == null) { return(ResponseMessage(getHttpResponse(HttpStatusCode.NotFound))); } ShopProducts shopOut = new ShopProducts(); shopOut.Id = shop.Id; shopOut.UserId = shop.UserId; shopOut.Title = shop.Title; shopOut.Description = shop.Description; shopOut.DescriptionFull = shop.DescriptionFull; shopOut.Views = shop.Views; shopOut.IsActive = shop.IsActive; shopOut.CreatedAt = shop.CreatedAt; shopOut.UpdatedAt = shop.UpdatedAt; shopOut.Products = new List <ProductOut>(); IList <Product> productsInShop = new List <Product>(); productsInShop = await db.Products.Where(p => p.ShopId == id& p.IsActive == 1).ToListAsync(); foreach (var product in productsInShop) { shopOut.Products.Add(await GetProductsForShop(product.Id)); } await IncrementView(id); return(Ok(shopOut)); }