示例#1
0
        public async Task <ShoperItem> Get(string shopid, string sku, string InventoryId)
        {
            ClaimsPrincipal  principal  = HttpContext.User as ClaimsPrincipal;
            var              UserId     = _userManager.GetUserId(principal);
            UsersShoperToken shop       = _dbContext.ShoperToken.First <UsersShoperToken>(x => (x.Id == Int32.Parse(shopid)));
            Inventory        inventory  = _dbContext.Inventory.SingleOrDefault <Inventory>(x => (x.Sku == sku && x.InventoryId == Int32.Parse(InventoryId)));
            ShoperItem       shoperItem = await ShoperItem.GetAsync(shop.Token, shop.ShopUrl, sku, inventory.Counter);

            return(shoperItem);
        }
示例#2
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));
        }
示例#3
0
        public async Task <bool> ChangeStock(string id, string num, string stock, string shopid, string inventoryid)
        {
            ClaimsPrincipal  principal = HttpContext.User as ClaimsPrincipal;
            var              UserId    = _userManager.GetUserId(principal);
            UsersShoperToken shop      = _dbContext.ShoperToken.First <UsersShoperToken>(x => (x.Id == Int32.Parse(shopid) && x.UserID == UserId));
            bool             response;
            int              i = 0;

            do
            {
                response = await ShoperItem.ChangeStock(shop.Token, shop.ShopUrl, id, stock);

                await Task.Delay(i);

                i += 1000;
            } while (response != true || i == 10000);

            dynamic a = new ExpandoObject();

            a.id    = id;
            a.stock = stock;
            a.set   = response;
            if (num == "0")
            {
                using (FileStream fs = System.IO.File.Create("reports\\reportofchanges" + shopid + "inventory" + inventoryid + ".json"))
                {
                    byte[] info = new UTF8Encoding(true).GetBytes("[" + JsonConvert.SerializeObject(a) + "]");
                    fs.Write(info, 0, info.Length);
                }
            }
            else
            {
                string json = "";
                using (StreamReader sr = System.IO.File.OpenText("reports\\reportofchanges" + shopid + "inventory" + inventoryid + ".json"))
                {
                    string s = "";
                    while ((s = sr.ReadLine()) != null)
                    {
                        json += s;
                    }
                }
                using (FileStream fs = System.IO.File.Create("reports\\reportofchanges" + shopid + "inventory" + inventoryid + ".json"))
                {
                    byte[] info = new UTF8Encoding(true).GetBytes(json.Trim(']') + ',' + JsonConvert.SerializeObject(a) + "]");
                    fs.Write(info, 0, info.Length);
                }
            }
            return(response);
        }
示例#4
0
        public async Task <List <ShoperItem> > Items(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)));
            List <Inventory> inventories = _dbContext.Inventory.Where <Inventory>(x => x.InventoryId == Int32.Parse(InventoryId)).ToList <Inventory>();
            string           skus        = "";

            foreach (Inventory inv in inventories)
            {
                skus += "\"" + inv.Sku + "\",";
            }
            List <ShoperItem> items = await ShoperItem.GetListAsync(shop.Token, shop.ShopUrl, skus.TrimEnd(','), inventories);

            return(items);
        }
示例#5
0
        public AjaxModel Post(ShoperItem form)
        {
            Inventory inventory = _dbContext.Inventory.SingleOrDefault <Inventory>(x => (x.Sku == form.Sku && x.InventoryId == Int32.Parse(form.InventoryId)));
            var       response  = new AjaxModel();

            if (inventory == null)
            {
                _dbContext.Add(new Inventory()
                {
                    Sku         = form.Sku,
                    Counter     = 1,
                    InventoryId = Int32.Parse(form.InventoryId)
                });
                response = new AjaxModel(form, "false");
            }
            else
            {
                inventory.Counter += 1;
                response           = new AjaxModel(form, "true");
            }
            _dbContext.SaveChanges();
            return(response);
        }