Exemplo n.º 1
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);
        }