public IActionResult ChangeStock(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)); Inventories inventories = _dbContext.Inventories.First <Inventories>(x => (x.ShopId == shop.Id.ToString() && x.UserID == UserId && x.Id == Int32.Parse(inventoryId))); if (inventories.Status == "Zakończona") { return(RedirectToAction("ShowReportOfChanges", new { shopId = shopId, inventoryId = inventoryId })); } string json = ""; try { using (StreamReader sr = System.IO.File.OpenText("reports\\acceptedshop" + shop.Id + "inventory" + inventoryId + ".json")) { string s = ""; while ((s = sr.ReadLine()) != null) { json += s; } } } catch { return(View("ChangeStock", new List <ReportOfChanges>())); } List <ReportOfChanges> reportOfChanges = JsonConvert.DeserializeObject <List <ReportOfChanges> >(json); return(View("ChangeStock", reportOfChanges)); }
public IActionResult ShowReportOfChanges(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)); Inventories inventories = _dbContext.Inventories.First <Inventories>(x => (x.ShopId == shop.Id.ToString() && x.UserID == UserId)); string json = ""; try { using (StreamReader sr = System.IO.File.OpenText("reports\\reportofchanges" + shop.Id + "inventory" + inventoryId + ".json")) { string s = ""; while ((s = sr.ReadLine()) != null) { json += s; } } } catch { return(View("ShowReportOfChanges", new Dictionary <string, string>())); } List <ReportResult> reportOfChanges = JsonConvert.DeserializeObject <List <ReportResult> >(json); return(View("ShowReportOfChanges", reportOfChanges)); }
public async Task <IActionResult> AddShoperToken(LoginDetails loginDetails) { RestClient client = new RestClient("https://" + loginDetails.ShopUrl); RestRequest request = new RestRequest("/webapi/rest/auth", Method.POST); request.AddParameter("client_id", loginDetails.Name); request.AddParameter("client_secret", loginDetails.Password); var response = await client.ExecuteAsync(request); if (response.IsSuccessful) { ClaimsPrincipal principal = HttpContext.User as ClaimsPrincipal; var UserId = _userManager.GetUserId(principal); ShoperAuthResponse shoperAuth = new ShoperAuthResponse(response.Content); UsersShoperToken shoperToken = new UsersShoperToken() { ExpireDate = shoperAuth.expire_date, ShopUrl = loginDetails.ShopUrl, Token = shoperAuth.access_token, UserID = UserId, }; _dbContext.ShoperToken.Add(shoperToken); _dbContext.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("AddShoperToken")); }
public async Task <IActionResult> AddInventory(string ShopId, string Name, string SKU, string Option, string Category) { ClaimsPrincipal principal = HttpContext.User as ClaimsPrincipal; var UserId = _userManager.GetUserId(principal); UsersShoperToken shop = _dbContext.ShoperToken.First <UsersShoperToken>(x => (x.UserID == UserId && x.Id == Int32.Parse(ShopId))); Inventories inventories = new Inventories() { ShopUrl = shop.ShopUrl, Sku = SKU, Category = Category, Name = Name, Option = Option, UserID = UserId, ShopId = ShopId, Status = "Otwarta" }; _dbContext.Inventories.Add(inventories); _dbContext.SaveChanges(); List <Inventories> _inventories = _dbContext.Inventories.Where <Inventories>(x => (x.UserID == UserId && x.ShopId == ShopId)).ToList <Inventories>(); ShopCategories shopCategories = await ShopCategories.GetCategories(shop.ShopUrl, shop.Token); Tuple <ShopCategories, string, List <Inventories> > tuple = new Tuple <ShopCategories, string, List <Inventories> >(shopCategories, ShopId, _inventories); return(View("Inventories", tuple)); }
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); }
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)); }
public async Task <IActionResult> Inventory(string ShopId) { ClaimsPrincipal principal = HttpContext.User as ClaimsPrincipal; var UserId = _userManager.GetUserId(principal); UsersShoperToken shop = _dbContext.ShoperToken.First <UsersShoperToken>(x => (x.UserID == UserId && x.Id == Int32.Parse(ShopId))); List <Inventories> inventories = _dbContext.Inventories.Where <Inventories>(x => (x.UserID == UserId && x.ShopId == ShopId)).ToList <Inventories>(); ShopCategories shopCategories = await ShopCategories.GetCategories(shop.ShopUrl, shop.Token); Tuple <ShopCategories, string, List <Inventories> > tuple = new Tuple <ShopCategories, string, List <Inventories> >(shopCategories, ShopId, inventories); return(View("Inventories", tuple)); }
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); }
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); }
public bool ChangeStatus(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)); Inventories inventory = _dbContext.Inventories.First <Inventories>(x => (x.Id == Int32.Parse(inventoryId) && x.ShopId == shop.Id.ToString())); inventory.Status = "Zakończona"; List <Inventory> _inventory = _dbContext.Inventory.Where <Inventory>(x => x.InventoryId == Int32.Parse(inventoryId)).ToList <Inventory>(); _dbContext.Inventory.RemoveRange(_inventory); _dbContext.SaveChanges(); System.IO.File.Delete("reports\\acceptedshop" + shopId + "inventory" + inventoryId + ".json"); System.IO.File.Delete("reports\\shop" + shopId + "inventory" + inventoryId + ".json"); return(true); }