Exemplo n.º 1
0
        public async Task <IActionResult> GenerateReport(string inventoryid, string shopid)
        {
            ClaimsPrincipal  principal   = HttpContext.User as ClaimsPrincipal;
            var              UserId      = _userManager.GetUserId(principal);
            UsersShoperToken shop        = _dbContext.ShoperToken.First <UsersShoperToken>(x => (x.Id == Int32.Parse(shopid)));
            Inventories      inventory   = _dbContext.Inventories.Single <Inventories>(x => (x.Id == Int32.Parse(inventoryid) && x.ShopId == x.ShopId && x.UserID == UserId));
            List <Inventory> inventories = _dbContext.Inventory.Where <Inventory>(x => x.InventoryId == Int32.Parse(inventoryid)).ToList <Inventory>();

            if (inventory.Status == "Zakończona")
            {
                return(RedirectToAction("ShowReportOfChanges", new { shopId = shopid, inventoryId = inventoryid }));
            }
            List <ReportOfChanges> report = new List <ReportOfChanges>();

            switch (inventory.Option)
            {
            case "SKU":
            {
                report = await ShoperItem.GetAllSkuListAsync(shop.Token, shop.ShopUrl, inventory.Sku, inventories);

                break;
            }

            case "Category&SKU":
            {
                report = await ShoperItem.GetAllSkuListAsync(shop.Token, shop.ShopUrl, inventory.Sku, inventories);

                //dodaj filtrowanie kategorii
                break;
            }

            case "Category":
            {
                report = await ShoperItem.GetAllCategoryListAsync(shop.Token, shop.ShopUrl, inventory.Category, inventories);

                break;
            }

            default:
                break;
            }
            try
            {
                using (FileStream fs = System.IO.File.Create("reports\\shop" + shopid + "inventory" + inventoryid + ".json"))
                {
                    byte[] info = new UTF8Encoding(true).GetBytes(JsonConvert.SerializeObject(report));
                    fs.Write(info, 0, info.Length);
                }
            }
            catch
            {
            }
            return(ReadReport(inventoryid, shopid));
        }