private ManageViewModel RecuperarItems(int id, bool onlySpawnables) { var capsuleDB = Database.Capsules.SingleOrDefault(p => p.CapsuleId == id && p.UserId == Username); if (capsuleDB == null) { return(null); } if (onlySpawnables) { var spawnables = ItemsCapsule.Where(p => p.PaysInterests).Select(s => s.ItemId); if (!spawnables.Contains(capsuleDB.ItemId)) { return(null); } } ManageViewModel model = new ManageViewModel(); LoadCapsule(capsuleDB, model); model.Items = capsuleDB.CapsulesItems.Select(p => new ItemCapsuleViewModel { CurrentItem = ItemBase.Create(ItemsXml, p.ItemId), Quantity = p.Quantity }).OrderBy(x => x.CurrentItem.Order).ToList(); return(model); }
private ActionResult GetItems(string groupId, bool ignoreZeroQuantity) { bool allGroups = groupId == GroupIdAll; if (!allGroups && !GroupsXml.Any(p => p.GroupId == groupId)) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, "GroupId does not exists")); } DateTime inicio = DateTime.Now; var enCapsules = Database.CapsulesItems .Where(s => s.Capsules.UserId == Username) .GroupBy(t => t.ItemId) .Select(u => new { ItemId = u.Key, CapsulesQuantity = u.Sum(v => v.Quantity) }).ToList(); var inventario = Database.InventoriesItems .Where(s => s.Inventories.UserId == Username) .Select(u => new { ItemId = u.ItemId, Quantity = u.Quantity }).ToList(); double elapsed = (DateTime.Now - inicio).TotalMilliseconds; var itemsGroups = ItemsXml .Where(z => (allGroups || z.GroupId == groupId) && (ignoreZeroQuantity || (inventario.Any(y => y.ItemId == z.ItemId) || enCapsules.Any(y => y.ItemId == z.ItemId)))) .Select(y => new { GroupId = y.GroupId, Item = ItemBase.Create(y), Quantity = inventario.SingleOrDefault(s => s.ItemId == y.ItemId) == null ? 0 : inventario.Single(s => s.ItemId == y.ItemId).Quantity, CapsulesQuantity = enCapsules.SingleOrDefault(s => s.ItemId == y.ItemId) == null ? 0 : enCapsules.Single(s => s.ItemId == y.ItemId).CapsulesQuantity }) .ToList(); if (itemsGroups.Count == 0) { return(Json(new { Result = false }, JsonRequestBehavior.DenyGet)); } var groups = itemsGroups .GroupBy(d => d.GroupId) .Select(p => new { GroupId = p.Key, Types = p.GroupBy(e => e.Item.TypeId) .Select(q => new { TypeId = q.Key, Quantity = q.Sum(f => f.Quantity), CapsulesQuantity = q.Sum(f => f.CapsulesQuantity), Items = q.Select(r => new { CurrentItem = r.Item, Quantity = r.Quantity, CapsulesQuantity = r.CapsulesQuantity }) }) }); return(Json(new { Result = true, Groups = groups }, JsonRequestBehavior.DenyGet)); }
public static ItemViewModelLight Create(IReadOnlyList <Item> itemsXml, string itemId) { ItemViewModelLight instance = new ItemViewModelLight(); if (!string.IsNullOrEmpty(itemId)) { instance.CurrentItem = ItemBase.Create(itemsXml, itemId); } return(instance); }
public ActionResult DateCapsule(DateGrouping grouping, string capsuleCode) { DateTime inicio = DateTime.Now; var reproduccionesDB = Database.SpawnsCapsulesItems.Where(p => p.SpawnsCapsules.Spawns.UserId == Username && (string.IsNullOrEmpty(capsuleCode) || p.SpawnsCapsules.CapsuleCode == capsuleCode)) .GroupBy(r => new { Date = DbFunctions.TruncateTime(r.SpawnsCapsules.Spawns.Date).Value, Code = r.SpawnsCapsules.CapsuleCode, ItemId = r.ItemId }) .Select(s => new { Code = s.Key.Code, Date = s.Key.Date, ItemId = s.Key.ItemId, Quantity = s.Sum(m => m.Quantity), }).ToList(); var filas = reproduccionesDB .GroupBy(r => new { Code = r.Code, Date = r.Date.GetResolvedDate(grouping) }) .Select(s => new FechaTotalViewModel { Code = s.Key.Code, Date = s.Key.Date, TotalQuantity = s.Sum(p => p.Quantity), Items = s.GroupBy(u => u.ItemId).Select(v => new ItemCapsuleViewModel { Quantity = v.Sum(w => w.Quantity), CurrentItem = ItemBase.Create(ItemsXml, v.First().ItemId) }) }).ToList(); var totales = reproduccionesDB .GroupBy(r => r.Code) .Select(s => new FechaTotalViewModel { Code = s.Key, Date = DateTime.MinValue, TotalQuantity = s.Sum(p => p.Quantity), Items = s.GroupBy(u => u.ItemId).Select(v => new ItemCapsuleViewModel { Quantity = v.Sum(w => w.Quantity), CurrentItem = ItemBase.Create(ItemsXml, v.First().ItemId) }) }).ToList(); var model = new ByDateViewModel(); model.Grouping = grouping; model.Capsules = reproduccionesDB.Select(p => p.Code).Distinct().ToList(); model.DateInfo = reproduccionesDB.GroupBy(p => p.Date.GetResolvedDate(grouping)).Select(q => new DateInfoModel { Date = q.Key, TotalCapsules = q.Select(z => z.Code).Distinct().Count(), TotalItems = q.Sum(r => r.Quantity), RealDays = (int)(q.Max(h => h.Date) - q.Min(i => i.Date)).TotalDays + 1 }).OrderByDescending(b => b.Date); model.Rows = filas; model.Totals = totales; TimeSpan tiempo = DateTime.Now.Subtract(inicio); return(View(model)); }
private LoadViewModel RecuperarItemsLoad(int id) { var capsuleDB = Database.Capsules.SingleOrDefault(p => p.CapsuleId == id && p.UserId == Username); if (capsuleDB == null) { return(null); } LoadViewModel model = new LoadViewModel(); LoadCapsule(capsuleDB, model); model.Items = capsuleDB.CapsulesItems.Select(p => new ItemLoadViewModel { CurrentItem = ItemBase.Create(ItemsXml, p.ItemId), CapsuleQuantity = p.Quantity, ItemQuantity = 0, LoadQuantity = 0 }).OrderBy(x => x.CurrentItem.Order).ToList(); var isCapsule = ItemsCapsule.Select(s => s.ItemId); var isKey = ItemsXml.Where(p => p.IsKey).Select(s => s.ItemId); var inventoryDB = Database.InventoriesItems.Where(p => p.Inventories.UserId == Username && !isCapsule.Contains(p.ItemId) && (!model.Properties.IsKeyLocker || isKey.Contains(p.ItemId))).ToList(); var inventories = inventoryDB.Select(q => new ItemLoadViewModel { CurrentItem = ItemBase.Create(ItemsXml, q.ItemId), CapsuleQuantity = 0, ItemQuantity = q.Quantity, LoadQuantity = 0 }).OrderBy(p => p.CurrentItem.Order).ToList(); foreach (var item in model.Items) { ItemLoadViewModel inv = inventories.SingleOrDefault(p => p.CurrentItem == item.CurrentItem); if (inv != null) { item.ItemQuantity = inv.ItemQuantity; inventories.Remove(inv); } } model.Items.AddRange(inventories); return(model); }
public ActionResult LastSpawn() { LastSpawnViewModel model = new LastSpawnViewModel(); model.TotalQuantity = 0; var last = Database.Spawns.Where(p => p.UserId == Username).OrderByDescending(q => q.Date).FirstOrDefault(); if (last == null) { return(View(model)); } model.SpawnDate = last.Date; var reproducciones = last.SpawnsCapsules .SelectMany(z => z.SpawnsCapsulesItems) .Select(s => new { Code = s.CapsuleCode, ItemId = s.ItemId, Quantity = s.Quantity }).ToList(); model.Capsules = reproducciones .GroupBy(p => p.Code) .Select(s => new Models.Capsules.ContentsViewModel { Code = s.Key, ItemsQuantity = s.Count(), Items = s.OrderBy(x => x.ItemId).Select(t => new ItemCapsuleViewModel { CurrentItem = ItemBase.Create(ItemsXml, t.ItemId), Quantity = t.Quantity }) }).ToList(); model.Totals = reproducciones .GroupBy(t => t.ItemId) .OrderBy(x => x.Key) .Select(q => new ItemCapsuleViewModel { CurrentItem = ItemBase.Create(ItemsXml, q.Key), Quantity = q.Sum(r => r.Quantity) }); model.TotalQuantity = reproducciones.Sum(p => p.Quantity); return(View(model)); }
public ActionResult TotalCapsule(string id) { var reproducciones = Database.SpawnsCapsulesItems.Where(p => p.SpawnsCapsules.Spawns.UserId == Username && (id == null || p.SpawnsCapsules.CapsuleCode == id)) .OrderBy(q => q.ItemId) .Select(s => new { Code = s.CapsuleCode, ItemId = s.ItemId, Quantity = s.Quantity, }).ToList(); var model = reproducciones.GroupBy(r => r.Code) .Select(s => new FechaTotalViewModel { Code = s.Key, TotalQuantity = s.Sum(p => p.Quantity), Items = s.GroupBy(u => u.ItemId).Select(v => new ItemCapsuleViewModel { Quantity = v.Sum(w => w.Quantity), CurrentItem = ItemBase.Create(ItemsXml, v.First().ItemId) }) }).ToList(); return(View(model)); }
public bool AddToInventory(ItemBase itembs) { itembs = itembs.Create(); InventorySlot freeslot = GetFreeInvSlot(); if (freeslot == null) { itembs.transform.position = UIOwner.transform.position; return(false); } itembs.SetOwner(UIOwner); itembs.ApplySockets(); itemPossesion.Add(itembs, freeslot); freeslot.Item = itembs; itembs.OnAddedToInventory(); itembs.Sleep(); return(true); }
void Update() { if (Input.GetKeyDown(KeyCode.Q)) { if (yes) { inventory.AddToInventory(ItemBase.Create("CZ")); } else { inventory.AddToInventory(ItemBase.Create("CHOCOLATE")); } yes = !yes; } if (Input.GetKeyDown(KeyCode.E)) { inventory.RemoveLastItem(); } }
private UnloadViewModel RecuperarItemsUnload(int id) { var capsuleDB = Database.Capsules.SingleOrDefault(p => p.CapsuleId == id && p.UserId == Username); if (capsuleDB == null) { return(null); } UnloadViewModel model = new UnloadViewModel(); LoadCapsule(capsuleDB, model); model.Items = capsuleDB.CapsulesItems.Select(p => new ItemUnloadViewModel { CurrentItem = ItemBase.Create(ItemsXml, p.ItemId), CapsuleQuantity = p.Quantity, UnloadQuantity = 0 }).OrderBy(x => x.CurrentItem.Order).ToList(); return(model); }
public JsonResult ByItemDate(DateGrouping grouping, int periods) { DateTime startDate = new DateTime(2000, 1, 1); // all data if (periods < 0) { periods = 4; } if (periods > 0) { switch (grouping) { case DateGrouping.Year: startDate = DateTime.Now.Date.GetResolvedDate(DateGrouping.Year).AddYears(1 - periods); break; case DateGrouping.Month: startDate = DateTime.Now.Date.GetResolvedDate(DateGrouping.Month).AddMonths(1 - periods); break; case DateGrouping.Week: startDate = DateTime.Now.Date.GetResolvedDate(DateGrouping.Week).AddDays((1 - periods) * 7); break; case DateGrouping.Day: default: startDate = DateTime.Now.Date.AddDays(1 - periods); break; } } string dateFormat = Resources.General.ResourceManager.GetString(string.Format("InterestsByDate_DateFormat_{0}", grouping.ToString())); var reproduccionesDB = Database.SpawnsCapsulesItems.Where(p => p.SpawnsCapsules.Spawns.UserId == Username && DbFunctions.TruncateTime(p.SpawnsCapsules.Spawns.Date).Value >= startDate) .GroupBy(r => new { Date = DbFunctions.TruncateTime(r.SpawnsCapsules.Spawns.Date).Value, Code = r.SpawnsCapsules.CapsuleCode, ItemId = r.ItemId }) .Select(s => new { Code = s.Key.Code, Date = s.Key.Date, ItemId = s.Key.ItemId, Quantity = s.Sum(m => m.Quantity), }).ToList(); var items = reproduccionesDB .GroupBy(r => new { Date = r.Date.GetResolvedDate(grouping) }) .Select(s => new DateInfoTotalModel { Date = s.Key.Date, FormattedDate = s.Key.Date.ToString(dateFormat), TotalCapsules = s.Select(h => h.Code).Distinct().Count(), TotalItems = s.Sum(p => p.Quantity), RealDays = (int)(s.Max(h => h.Date) - s.Min(i => i.Date)).TotalDays + 1, Items = s.GroupBy(u => u.ItemId).Select(v => new { ItemId = v.Key, Cantidad = v.Sum(w => w.Quantity) }).ToDictionary(m => m.ItemId, n => n.Cantidad) }).ToList(); var totals = reproduccionesDB .GroupBy(q => q.ItemId) .Select(i => new ItemCapsuleViewModel { CurrentItem = ItemBase.Create(ItemsXml, i.Key), Quantity = i.Sum(j => j.Quantity) }).OrderBy(k => k.CurrentItem.Order); var highests = reproduccionesDB .GroupBy(r => new { Date = r.Date.GetResolvedDate(grouping), ItemId = r.ItemId }) .Select(s => new { ItemId = s.Key.ItemId, Cantidad = s.Sum(p => p.Quantity) }) .GroupBy(h => h.ItemId) .Select(i => new { ItemId = i.Key, Maximo = i.Max(j => j.Cantidad) }) .ToDictionary(h => h.ItemId, i => i.Maximo); var model = new ByDateTotalViewModel(); model.Grouping = grouping; model.DateInfo = items.OrderByDescending(b => b.Date); model.Totals = totals; model.Highests = highests; model.TotalItems = totals.Sum(p => p.Quantity); model.Items = model.Totals.Select(p => p.CurrentItem.ItemId).ToArray(); return(Json(model, JsonRequestBehavior.AllowGet)); }
public ActionResult DifferenceData() { if (Username != "*****@*****.**" && Username != "*****@*****.**") { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Invalid user.")); } DifferenceViewModel model = new DifferenceViewModel(); string userIdA = Username; string userIdB = (Username == "*****@*****.**" ? "*****@*****.**" : "*****@*****.**"); model.OrigUserId = MyInventory.Utils.GetUsernamFromEmail(userIdA); model.DestUserId = MyInventory.Utils.GetUsernamFromEmail(userIdB); var inventoryA = Database.InventoriesItems .Where(s => s.Inventories.UserId == userIdA) .Select(u => new ItemQuantity { ItemId = u.ItemId, Quantity = u.Quantity }).ToList(); var inventoryB = Database.InventoriesItems .Where(s => s.Inventories.UserId == userIdB) .Select(u => new ItemQuantity { ItemId = u.ItemId, Quantity = u.Quantity }).ToList(); var capsulesA = Database.CapsulesItems .Where(s => s.Capsules.UserId == userIdA) .GroupBy(t => t.ItemId) .Select(u => new ItemQuantity { ItemId = u.Key, Quantity = u.Sum(v => v.Quantity) }); var capsulesB = Database.CapsulesItems .Where(s => s.Capsules.UserId == userIdB) .GroupBy(t => t.ItemId) .Select(u => new ItemQuantity { ItemId = u.Key, Quantity = u.Sum(v => v.Quantity) }); foreach (var itemC in capsulesA) { var itemI = inventoryA.SingleOrDefault(f => f.ItemId == itemC.ItemId); if (itemI == null) { inventoryA.Add(new ItemQuantity { ItemId = itemC.ItemId, Quantity = itemC.Quantity }); } else { itemI.Quantity += itemC.Quantity; } } foreach (var itemC in capsulesB) { var itemI = inventoryB.SingleOrDefault(f => f.ItemId == itemC.ItemId); if (itemI == null) { inventoryB.Add(new ItemQuantity { ItemId = itemC.ItemId, Quantity = itemC.Quantity }); } else { itemI.Quantity += itemC.Quantity; } } model.Groups = GroupsXml .Select(p => new GroupDifferenceViewModel { GroupId = p.GroupId, Types = p.Types.Select(q => new TypeDifferenceViewModel { TypeId = q.TypeId, Items = q.Items.Select(r => new ItemDifferenceViewModel { CurrentItem = ItemBase.Create(r), OrigQuantity = inventoryA.SingleOrDefault(s => s.ItemId == r.ItemId) == null ? 0 : inventoryA.Single(s => s.ItemId == r.ItemId).Quantity, DestQuantity = inventoryB.SingleOrDefault(s => s.ItemId == r.ItemId) == null ? 0 : inventoryB.Single(s => s.ItemId == r.ItemId).Quantity }).ToList() }).ToList() }).ToList(); model.Groups.RemoveAll(p => p.OrigDifference == 0 && p.DestDifference == 0); foreach (var group in model.Groups) { group.Types.RemoveAll(p => p.OrigDifference == 0 && p.DestDifference == 0); foreach (var type in group.Types) { type.Items.RemoveAll(p => p.OrigDifference == 0 && p.DestDifference == 0); } } return(Json(model, JsonRequestBehavior.AllowGet)); }