public ActionResult UpdateItemAcquisition( [Bind(Prefix = "ItemAcquisition")] ItemAcquisition model, [Bind(Prefix = "ComponentAcquisitions")] List <ComponentAcquisition> compModel) { if (ModelState.IsValid) { User user = _uow.GetRepo <UserRepository>().GetByUsername(User.Identity.Name); model.UserID = user.ID; WarframeItem item = _itemUtils.GetByUniqueName(model.ItemUniqueName); ItemCategory category = _uow.GetRepo <ItemCategoryRepository>().GetByID(item.ItemCategoryID); if (!category.CanBeMastered) { model.IsMastered = false; } ItemAcquisition existing = _uow.GetRepo <ItemAcquisitionRepository>().GetByPrimaryKeys(user.ID, model.ItemUniqueName); if (existing == null) { _uow.GetRepo <ItemAcquisitionRepository>().Add(model); } else { _uow.GetRepo <ItemAcquisitionRepository>().Update(model); } if (compModel != null && compModel.Any()) { foreach (ComponentAcquisition ca in compModel) { ca.UserID = user.ID; ComponentAcquisition existingComp = _uow.GetRepo <ComponentAcquisitionRepository>().GetByPrimaryKeys(user.ID, ca.ComponentUniqueName, ca.ItemUniqueName); if (existingComp == null) { _uow.GetRepo <ComponentAcquisitionRepository>().Add(ca); } else { _uow.GetRepo <ComponentAcquisitionRepository>().Update(ca); } } } return(Json(new { success = true, itemName = model.ItemUniqueName, view = RenderViewAsync("AcquisitionIcon", model).Result })); } return(Json(new { success = false })); }
public PrimeWishlistViewModel Load(UnitOfWork uow, WarframeItemUtilities itemUtils, ClaimsPrincipal user, AppSettings appSettings) { int?userID = null; if (user.Identity.IsAuthenticated) { userID = int.Parse(user.FindFirstValue(ClaimTypes.NameIdentifier)); } List <WarframeItem> allItems = itemUtils.GetAll(); List <WarframeItem> primes = allItems.Where(x => x.IsPrime).ToList(); if (userID.HasValue) { ItemAcquisitions = uow.GetRepo <ItemAcquisitionRepository>().GetByUserID(userID.Value); } else { ItemAcquisitions = new List <ItemAcquisition>(); } List <ItemAcquisition> ias = ItemAcquisitions.Where(x => x.IsAcquired).ToList(); if (userID.HasValue) { ComponentAcquisitions = uow.GetRepo <ComponentAcquisitionRepository>().GetByUserID(userID.Value); } else { ComponentAcquisitions = new List <ComponentAcquisition>(); } List <PrimeRelease> releases = uow.GetRepo <PrimeReleaseRepository>().GetAll(); List <PrimeRelease> unvaulted = releases.Where(x => x.IsReleasedFromVault).ToList(); List <string> unvaultedUniqueNames = new List <string>(); if (unvaulted.Any()) { unvaultedUniqueNames.AddRange(unvaulted.Select(x => x.WarframeUniqueName)); unvaultedUniqueNames.AddRange(unvaulted.Select(x => x.Item1UniqueName)); unvaultedUniqueNames.AddRange(unvaulted.Select(x => x.Item2UniqueName)); unvaultedUniqueNames.AddRange(unvaulted.Select(x => x.Item3UniqueName)); } PrimeWishlist = primes.Where(x => !x.IsExclusive && (!x.IsVaulted || unvaultedUniqueNames.Contains(x.UniqueName)) && !ias.Select(y => y.ItemUniqueName).Contains(x.UniqueName)).ToList(); foreach (WarframeItem item in PrimeWishlist) { if (string.IsNullOrWhiteSpace(item.ReleaseDate)) { PrimeRelease primeRelease = releases.SingleOrDefault(x => x.WarframeUniqueName == item.UniqueName || x.Item1UniqueName == item.UniqueName || x.Item2UniqueName == item.UniqueName || x.Item3UniqueName == item.UniqueName); if (primeRelease != null) { item.ReleaseDate = primeRelease.ReleaseDate.ToString("yyyy MM dd"); } } if (item.Components != null) { item.Components = item.Components.OrderByDescending(x => x.Name == "Blueprint").ThenBy(x => x.Name == "Orokin Cell").ThenBy(x => x.Name).ToList(); } } PrimeWishlist = PrimeWishlist.OrderBy(x => x.ReleaseDate).ToList(); #region Needed Relics NeededRelics = new List <WarframeItem>(); ItemCategory cat = uow.GetRepo <ItemCategoryRepository>().GetByCodexSection(CodexSection.Relics).FirstOrDefault(); List <WarframeItem> allRelics = itemUtils.GetByCategoryID(cat.ID); foreach (WarframeItem item in PrimeWishlist.Where(x => !x.IsVaulted)) { if (item.Components != null) { foreach (Component comp in item.Components) { ComponentAcquisition ca = ComponentAcquisitions .SingleOrDefault(x => x.IsAcquired && x.ItemUniqueName == item.UniqueName && x.ComponentUniqueName == comp.UniqueName); if (ca == null) { if (comp.Drops != null && comp.Drops.Any()) { foreach (Drop drop in comp.Drops) { string[] split = drop.Location.Split(" ", StringSplitOptions.RemoveEmptyEntries); if (split.Length > 1) { string relicName = split[0] + " " + split[1]; var relic = allRelics.SingleOrDefault(x => x.Name.StartsWith(relicName + " ")); //var relic = allRelics.Where(x => x.Name.Substring(0, 8) == drop.Location.Substring(0, 8)); if (relic != null && !relic.IsVaulted) { NeededRelics.Add(relic); } } } } } } } } NeededRelics = NeededRelics.Distinct() .OrderByDescending(x => x.Name.StartsWith("Lith")) .ThenByDescending(x => x.Name.StartsWith("Meso")) .ThenByDescending(x => x.Name.StartsWith("Neo")) .ThenByDescending(x => x.Name).ToList(); #endregion return(this); }
public ItemModalViewModel Load(WarframeItem warframeItem, ItemCategory itemCategory, ClaimsPrincipal user, UnitOfWork uow, WarframeItemUtilities itemUtils) { WarframeItem = warframeItem; ItemCategory = itemCategory; int?userID = null; if (user.Identity.IsAuthenticated) { userID = int.Parse(user.FindFirstValue(ClaimTypes.NameIdentifier)); ItemAcquisition = uow.GetRepo <ItemAcquisitionRepository>().GetByPrimaryKeys(userID.Value, WarframeItem.UniqueName); if (ItemAcquisition == null) { ItemAcquisition = new ItemAcquisition { UserID = userID.Value, ItemUniqueName = WarframeItem.UniqueName } } ; } if (WarframeItem.Components != null && WarframeItem.Components.Any()) { WarframeItem.Components = WarframeItem.Components.OrderByDescending(x => x.Name == "Blueprint").ThenBy(x => x.Name == "Orokin Cell").ThenBy(x => x.Name).ToList(); if (userID.HasValue) { ComponentAcquisitions = uow.GetRepo <ComponentAcquisitionRepository>() .GetByItemUniqueNameAndUserID(WarframeItem.UniqueName, userID.Value); } else { ComponentAcquisitions = new List <ComponentAcquisition>(); } ItemCategory cat = uow.GetRepo <ItemCategoryRepository>().GetByCodexSection(CodexSection.Relics).FirstOrDefault(); List <WarframeItem> relics = itemUtils.GetByCategoryID(cat.ID); int index = 0; foreach (Component comp in WarframeItem.Components) { ComponentAcquisition ca = ComponentAcquisitions .SingleOrDefault(x => x.ComponentUniqueName == comp.UniqueName); if (ca == null) { ComponentAcquisitions.Add(new ComponentAcquisition { UserID = userID ?? 0, ComponentUniqueName = comp.UniqueName, ItemUniqueName = WarframeItem.UniqueName, ComponentName = comp.Name }); } else { ca.ComponentName = comp.Name; } if (comp.Drops != null && comp.Drops.Any()) { for (int i = comp.Drops.Count - 1; i >= 0; i--) { var relic = relics.SingleOrDefault(x => x.Name == comp.Drops[i].Location); //if (relic != null && relic.IsVaulted) { // comp.Drops.RemoveAt(i); //} } } index++; } ComponentAcquisitions = ComponentAcquisitions.OrderByDescending(x => x.ComponentName == "Blueprint").ThenBy(x => x.ComponentName == "Orokin Cell").ThenBy(x => x.ComponentName).ToList(); } return(this); } }