private dynamic RouteEvent() { try { //RecipeItem.ResetId(); sql.Open(WebSettings.Settings.CreateDescription()); DataService db = new DataService(sql); var knightRidersCollection = CrossoutDataService.Instance.KnightRidersCollection; var statusModel = db.SelectStatus(); KnightRidersModel knightRidersModel = new KnightRidersModel(); List <int> containedItemIDs = new List <int>(); foreach (var item in knightRidersCollection.EventItems) { foreach (var ingredient in item.Ingredients) { if (!containedItemIDs.Contains(ingredient.Id)) { containedItemIDs.Add(ingredient.Id); } } if (item.Id != null) { containedItemIDs.Add((int)item.Id); } } knightRidersModel.ContainedItems = db.SelectListOfItems(containedItemIDs); foreach (var item in knightRidersCollection.EventItems) { decimal sellSum = 0; decimal buySum = 0; foreach (var ingredient in item.Ingredients) { ingredient.Name = knightRidersModel.ContainedItems[ingredient.Id].Name; ingredient.SellPrice = knightRidersModel.ContainedItems[ingredient.Id].SellPrice; ingredient.BuyPrice = knightRidersModel.ContainedItems[ingredient.Id].BuyPrice; ingredient.FormatSellPrice = PriceFormatter.FormatPrice(ingredient.SellPrice); ingredient.FormatBuyPrice = PriceFormatter.FormatPrice(ingredient.BuyPrice); sellSum += ingredient.SellPrice * ingredient.Amount / knightRidersModel.ContainedItems[ingredient.Id].Amount; buySum += ingredient.BuyPrice * ingredient.Amount / knightRidersModel.ContainedItems[ingredient.Id].Amount; } if (item.Id != null) { item.SellPrice = knightRidersModel.ContainedItems[(int)item.Id].SellPrice; item.BuyPrice = knightRidersModel.ContainedItems[(int)item.Id].BuyPrice; item.FormatSellPrice = PriceFormatter.FormatPrice(item.SellPrice); item.FormatBuyPrice = PriceFormatter.FormatPrice(item.BuyPrice); } item.FormatSellSum = PriceFormatter.FormatPrice(sellSum); item.FormatBuySum = PriceFormatter.FormatPrice(buySum); item.TotalSellSum = sellSum; item.TotalBuySum = buySum; item.FormatTotalSellSum = PriceFormatter.FormatPrice(sellSum); item.FormatTotalBuySum = PriceFormatter.FormatPrice(buySum); } knightRidersModel.EventItems = knightRidersCollection.EventItems; knightRidersModel.Status = statusModel; return(View["event", knightRidersModel]); } catch { return(Response.AsRedirect("/")); } }
private dynamic RoutePackages() { try { //RecipeItem.ResetId(); sql.Open(WebSettings.Settings.CreateDescription()); DataService db = new DataService(sql); var packagesCollection = CrossoutDataService.Instance.PremiumPackagesCollection; var statusModel = db.SelectStatus(); var appPrices = db.SelectAllSteamPrices(); PremiumPackagesModel packagesModel = new PremiumPackagesModel(); List <int> itemIDs = new List <int>(); //Load contained items foreach (var package in packagesCollection.Packages) { foreach (var itemID in package.MarketPartIDs) { if (!itemIDs.Contains(itemID)) { itemIDs.Add(itemID); } } } packagesModel.ContainedItems = db.SelectListOfItems(itemIDs); //Calc prizes foreach (var package in packagesCollection.Packages) { package.Prices = appPrices.Find(x => x.Id == package.SteamAppID).Prices; decimal sellSum = 0; decimal buySum = 0; foreach (var id in package.MarketPartIDs) { sellSum += packagesModel.ContainedItems[id].SellPrice; buySum += packagesModel.ContainedItems[id].BuyPrice; } package.FormatSellSum = PriceFormatter.FormatPrice(sellSum); package.FormatBuySum = PriceFormatter.FormatPrice(buySum); package.TotalSellSum = sellSum + (package.RawCoins * 100); package.TotalBuySum = buySum + (package.RawCoins * 100); package.FormatTotalSellSum = PriceFormatter.FormatPrice(sellSum + (package.RawCoins * 100)); package.FormatTotalBuySum = PriceFormatter.FormatPrice(buySum + (package.RawCoins * 100)); foreach (var price in package.Prices) { if (price != null && price.Final != 0) { price.FormatFinal = PriceFormatter.FormatPrice(price.Final); price.FormatSellPriceDividedByCurrency = PriceFormatter.FormatPrice(package.TotalSellSum / ((decimal)price.Final / 100)); price.FormatBuyPriceDividedByCurrency = PriceFormatter.FormatPrice(package.TotalBuySum / ((decimal)price.Final / 100)); } } } //Add all possible categories to dict var listOfCategories = new List <int>(); listOfCategories.Clear(); listOfCategories.Add(1); listOfCategories.Add(99); foreach (var package in packagesCollection.Packages) { if (!listOfCategories.Contains(package.Category) && package.Category != 0) { listOfCategories.Add(package.Category); } } listOfCategories.Sort(); foreach (var category in listOfCategories) { packagesModel.Packages.Add(category, new List <PremiumPackage>()); } //Categorize foreach (var package in packagesCollection.Packages) { if (package.Prices.Any(x => x.Final != 0)) { if (package.Category == 0) { package.Category = 1; } } else { package.Category = 99; } packagesModel.Packages[package.Category].Add(package); } packagesModel.Status = statusModel; return(View["packages", packagesModel]); } catch { return(Response.AsRedirect("/")); } }