public async Task <List <PortfolioItem> > UpdateSoldToDb(StockXAccount login) { List <PortfolioItem> ListedItems = await login.GetAllPending(); if (ListedItems == null) { Db.UpdateOnly(() => new StockXAccount() { AccountThread = "", NextAccountInteraction = DateTime.Now.AddMinutes(1) }, A => A.Id == login.Id); return(null); } foreach (var A in ListedItems) { if (UpdateToSold(login, A)) { ListingExtensions.CreateStockXListingEvent("Sold", A.ChainId, A.SkuUuid, (int)A.LocalAmount, login.UserId, "Sold"); Db.UpdateAdd(() => new Inventory() { TotalSold = 1 }, Db.From <Inventory>().Where(Ab => Ab.UserId == login.UserId && Ab.Sku == A.SkuUuid)); await StockxListingEvent.Sold(A, login); } } return(ListedItems); }
private async Task <bool> CreateAnyNewInventory(StockXAccount login, List <PortfolioItem> ListedItems) { var Created = false; var AllInventory = Db.Select(Db.From <Inventory>().Where(A => A.UserId == login.UserId && A.StockXAccountId == login.Id && A.Active && A.Quantity > 0)); var AllListed = Db.Select(Db.From <StockXListedItem>().Where(A => A.UserId == login.UserId && A.Id == login.Id && !A.Sold)); var UnListedInventory = AllInventory.Where(A => !ListedItems.Any(B => B.SkuUuid == A.Sku)); if (ListedItems.Count > 0) { var Deleted = AllListed.Where(A => !ListedItems.Any(B => B.ChainId == A.ChainId)); foreach (var Delete in Deleted) { Db.Delete(Delete); } } foreach (var Listling in ListedItems) { if (Db.Exists(Db.From <StockXListedItem>().Where(A => A.UserId == login.UserId && A.AccountId == login.Id && A.ChainId == Listling.ChainId))) { continue; } StockXListedItem Item = Listling; Item.UserId = login.UserId; Item.AccountId = login.Id; Db.Insert(Item); } foreach (var tory in UnListedInventory) { var Listing = await login.MakeListing(tory.StockXUrl, tory.Sku, tory.StartingAsk, StockXAccount.MakeTimeString()); if ((int)Listing.Code > 399 && (int)Listing.Code < 500) { throw new NeedsVerificaitonException(login); } if (Listing.Code == System.Net.HttpStatusCode.OK) { StockXListedItem Item = Listing.RO.PortfolioItem; Item.UserId = login.UserId; Item.AccountId = tory.StockXAccountId; Db.Insert(Item); Db.UpdateAdd(() => new Inventory() { Quantity = -1 }, Ab => Ab.Id == tory.Id); AuditExtensions.CreateAudit(Db, login.Id, "StockxListingGetter", "Inventory Created", Listing.RO.PortfolioItem.ChainId); Created = true; await StockxListingEvent.Listed(Item, login); continue; } return(false); //error 500+ -- their server is down end task. } return(Created); }
private void DisableAccountDuetoLoginFailure(StockXAccount Account) { Db.UpdateOnly(() => new StockXAccount() { Disabled = true, LoginFails = Account.LoginFails, NextVerification = Account.NextVerification, AccountThread = "" }, A => A.Id == Account.Id); Task.WaitAll(StockxListingEvent.Disabled(Account)); }