public ActionResult EditTheItem(int id, ItemTagsLocation itemTagsLocation) { NavLayout(); var itemToEdit = _repo.Items.FindByCondition(i => i.ItemId == id).SingleOrDefault(); itemToEdit = itemTagsLocation.Items; _repo.Items.Update(itemToEdit); var locationToEdit = _repo.LocationPlace.FindByCondition(l => l.LocationId == itemToEdit.LocationId).SingleOrDefault(); locationToEdit = itemTagsLocation.LocationPlace; _repo.LocationPlace.Update(locationToEdit); ItemTags itemTags = new ItemTags(); foreach (Tags tag in itemTagsLocation.Tags) { var items = _repo.ItemTags.FindByCondition(i => i.TagsId == tag.TagId).SingleOrDefault(); var tagToEdit = _repo.Tags.FindByCondition(t => t.TagId == items.TagsId).SingleOrDefault(); tagToEdit.Name = tag.Name; _repo.Tags.Update(tagToEdit); } _repo.Save(); try { return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <IActionResult> AddItem(ItemTagsLocation itemTagsLocation) { NavLayout(); //finds the logged in user var loggedInRoboDexer = FindLoggedInRoboDexer(); //adds the item's location to the location table LocationPlace locationPlace = new LocationPlace(); locationPlace.MainLocation = itemTagsLocation.LocationPlace.MainLocation; locationPlace.SecondaryLocation = itemTagsLocation.LocationPlace.SecondaryLocation; _repo.LocationPlace.Create(locationPlace); _repo.Save(); //adds all info into the item object and saves var itemObject = itemTagsLocation.Items; itemObject.LocationId = locationPlace.LocationId; itemObject.Price = itemTagsLocation.Items.Price; itemObject.TimeAdded = itemTagsLocation.Items.TimeAdded; _repo.Items.Create(itemObject); _repo.Save(); //adds the item to the user's inventory Inventory inventory = new Inventory(); inventory.ItemId = itemObject.ItemId; inventory.RoboDexerId = loggedInRoboDexer.RoboDexerId; _repo.Inventory.Create(inventory); _repo.Save(); //here the logic splits user input into spereate tags, adds tags to the table, and //then populates the itemtags table with the tags/item ids var listOfTags = itemTagsLocation.TagsInitial.Name.Split(' ').ToList(); foreach (string tag in listOfTags) { Tags tags = new Tags(); tags.Name = tag; _repo.Tags.Create(tags); _repo.Save(); ItemTags itemTags = new ItemTags(); itemTags.ItemId = itemObject.ItemId; itemTags.TagsId = tags.TagId; _repo.ItemTags.Create(itemTags); _repo.Save(); } return(RedirectToAction("Index")); }
//------------------------------------------------------------ // Common //------------------------------------------------------------ public Item(uint id, Items items) : base(id) { Items = items; Images = new Images(this); Tags = new ItemTags(this); Tags.CollectionChanged += OnTagsChanged; Images.CollectionChanged += OnImagesChanged; Images.PropertyChanged += OnImagesChanged; PropertyChanged += OnUpdateCache; // needs to be called manually since the delegate // wasn't set when the id was changed. UpdateCache(); }
public int AssignTag(ItemTags item) { List <ItemTags> repetitions = new List <ItemTags>(); repetitions = ItemTagList.Where(e => e.ItemId == item.ItemId).ToList(); if (repetitions.Count < 10) { ItemTagList.Add(item); } else { Console.WriteLine("Too many tags assigned to that task"); } return(repetitions.Count); }
public void SortItems() { #if DEBUG Log.Info("Sort items."); #endif var sorted = Items.Data.Values.Where(s => !s.HideFromAll); foreach (var v in Selected.AssociatedMaps) { sorted = sorted.Where(s => s.Maps.ContainsKey(v + "")); } ChampionData cd; foreach (var v in Selected.AssociatedChampions) { cd = Champions.Data.Values.FirstOrDefault(s => s.Key.Equals(v)); if (cd != null) { sorted = sorted.Where(s => string.IsNullOrEmpty(s.RequiredChampion) || s.RequiredChampion.Equals(cd.Name)); } } if (!string.IsNullOrEmpty(SortItemName)) { sorted = sorted.Where(s => s.Name.IndexOf(SortItemName, StringComparison.OrdinalIgnoreCase) > -1); } var tag = ItemTags.FirstOrDefault(s => s.IsChecked == true); if (tag != null) { if (!string.IsNullOrEmpty(tag.Tag)) { sorted = sorted.Where(s => s.Tags.Contains(tag.Tag)); } } SortedItems = sorted; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SortedItems")); }
public void Seed(int dbSize, List <MasterItem> items, List <MasterCustomer> customers, List <string> tags = null) { Dictionary <string, long> tagger = new Dictionary <string, long>(); Dictionary <long, Customer> customerdictionary = new Dictionary <long, Customer>(); Dictionary <long, Item> itemdictionary = new Dictionary <long, Item>(); Console.WriteLine("Adding customers"); //Then insert customers into the db foreach (MasterCustomer customer in customers) { Customer tmpCus = new Customer { ID = customer.Id, Age = customer.Age, Email = customer.Email, Gender = customer.Gender }; Customers.Add(tmpCus); SaveChanges(); customerdictionary.Add(tmpCus.ID, tmpCus); } //Dbsize should correspond to the amount of sales already exisitng in the db, which it should be seeded with. //Therefore we need to generate customers, and items. Console.WriteLine("Adding tags"); foreach (var tag in tags) { Tag newtag = new Tag { Name = tag }; Tags.Add(newtag); SaveChanges(); tagger.Add(newtag.Name, newtag.ID); } Console.WriteLine("Adding items"); //First insert items into the db foreach (MasterItem item in items) { Item dbItem = new Item { ID = item.Id, Name = item.Name, Price = item.Price }; itemdictionary.Add(item.Id, dbItem); Items.Add(dbItem); long tmp = -1; tagger.TryGetValue(item.Tag1, out tmp); ItemTags.Add(new TagItems { ItemId = item.Id, TagId = tmp }); if (item.Tag2 != null) { tagger.TryGetValue(item.Tag2, out tmp); ItemTags.Add(new TagItems { ItemId = item.Id, TagId = tmp }); } if (item.Tag3 != null) { tagger.TryGetValue(item.Tag3, out tmp); ItemTags.Add(new TagItems { ItemId = item.Id, TagId = tmp }); } } Console.WriteLine("Gen seed"); //Then generate seeded sales Random customerSelecter = new Random(123456); Random itemAmountSelector = new Random(12341); Random itemTypeSelector = new Random(634784); Random itemSelecter = new Random(6463526); Random dateSelecotr = new Random(3435468); Random satisfactionSelecotr = new Random(39843); Random StoreSelecotr = new Random(74626); DateTime startDate = new DateTime(2015, 1, 1); DateTime endDate = new DateTime(2020, 1, 1); int range = (endDate - startDate).Days; MeasurementTool tool = new MeasurementTool(0, 0, 0, ""); for (int i = 1; i <= dbSize; i++) { List <Sale> sameSale = new List <Sale>(); //Define Once long tmpcid = (long)customerSelecter.Next(1, customers.Count); Customer customer = null; customerdictionary.TryGetValue(tmpcid, out customer); //Define items to buy int itemsToBuy = itemTypeSelector.Next(1, 5); long? tmpSaleId = null; List <long> idUsed = new List <long>(); for (int j = 0; j < itemsToBuy; j++) { long tmpiid = (long)itemSelecter.Next(1, items.Count); if (!idUsed.Contains(tmpiid)) { idUsed.Add(tmpiid); itemdictionary.TryGetValue(tmpiid, out Item itemtobuy); var tmpSale = new Sale { //ID = tmpSaleId, Date = startDate.AddDays(dateSelecotr.Next(range)), ItemId = itemtobuy.ID, ItemName = itemtobuy.Name, ItemPrice = itemtobuy.Price, ItemQuantity = itemAmountSelector.Next(1, 5), CustomerId = customer.ID, CustomerAge = customer.Age, CustomerEmail = customer.Email, CustomerGender = customer.Gender, CustomerSatisfactoryNumber = satisfactionSelecotr.Next(0, 10), CouponUsed = false, PurchaseMethod = "Card", StoreLocation = StoreLocation.Locations[StoreSelecotr.Next(0, 9)] }; Sales.Add(tmpSale); Console.WriteLine(tmpSale.ID); tmpSaleId = tmpSale.ID; } else { break; } } } //Then insert seeded sales into the db SaveChanges(); }
public bool UpdateItemControl() { bool success = false; flowLayoutPanelItems2.SuspendLayout(); if (flowLayoutPanelItems2.Controls.Count > 0) { List <Control> ctrls = flowLayoutPanelItems2.Controls.Cast <Control>().ToList(); flowLayoutPanelItems2.Controls.Clear(); foreach (Control c in ctrls) { c.Dispose(); } } try { foreach (CreateItemDiv item in getItemsFromServer.itemsPrepared) { string version = getItemsFromServer.itemsPrepared[0].thisVersion; string file = string.Format(@"{0}\Data\Items\Images\{1}\{2}", PublicStaticVariables.thisAppDataDir, version, item.aItem.Image.Sprite); string dir = string.Format(@"{0}\Data\Items\Images\{1}", PublicStaticVariables.thisAppDataDir, version); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } Image imageItem = Image.FromFile(file); //Creating this control is the slowest part of this code ItemControl itemControl = new ItemControl(form1, this); itemControl.ItemCostLabel = item.aItem.Gold.TotalPrice.ToString(); Image image = CommonMethods.cropImage(imageItem, new Rectangle(item.aItem.Image.X, item.aItem.Image.Y, item.aItem.Image.Width, item.aItem.Image.Height)); itemControl.ItemImage = image; itemControl.Name = "ItemControl " + item.aItem.Name; itemControl.item = item; List <string> temp = new List <string>(); if (item.aItem.Tags == null) { temp.Add("noTag"); itemControl.Tag = temp; } else { temp = item.aItem.Tags; } ItemTags itemTags = new ItemTags(); itemTags.ItemName = item.aItem.Name; itemTags.Tags = temp; itemControl.Tag = itemTags; flowLayoutPanelItems2.Controls.Add(itemControl); } success = true; } catch (Exception ex) { MessageBox.Show(ex.ToString()); success = false; } flowLayoutPanelItems2.ResumeLayout(); return(success); }
public async Task <string> Refresh(int id) { DataController data = new DataController(); string key = data.Key(); string status; using (var client = new HttpClient()) { try { client.BaseAddress = new Uri("https://na1.api.riotgames.com/"); var response = await client.GetAsync("lol/static-data/v3/items/" + id.ToString() + "?locale=en_US&tags=all&api_key=" + key); response.EnsureSuccessStatusCode(); var stringResult = await response.Content.ReadAsStringAsync(); var item = JsonConvert.DeserializeObject <RootObject>(stringResult); Item i = new Item(); ItemGold itemGold = new ItemGold(); ItemImage itemImage = new ItemImage(); List <ItemInto> itemInto = new List <ItemInto>(); ItemMaps itemMaps = new ItemMaps(); ItemStats itemStats = new ItemStats(); ItemTags itemTags = new ItemTags(); i.ItemID = item.id; i.Description = item.description; i.Plaintext = item.plaintext; i.Name = item.name; i.SanitizedDescription = item.sanitizedDescription; itemGold.ItemID = i.ItemID; itemGold.Base = item.gold.@base; itemGold.Total = item.gold.total; itemGold.Sell = item.gold.sell; itemGold.Purchasable = item.gold.purchasable; itemImage.ItemID = i.ItemID; itemImage.Full = item.image.full; itemImage.Sprite = item.image.sprite; itemImage.Group = item.image.group; itemImage.X = item.image.x; itemImage.Y = item.image.y; itemImage.W = item.image.w; itemImage.H = item.image.h; List <int> itemIntoItems = new List <int>(); for (int c = 0; c < item.into.Count(); c++) { itemIntoItems.Add(Convert.ToInt32(item.into[c])); } foreach (int itemIntoItemID in itemIntoItems) { itemInto.Add(new ItemInto { ItemID = item.id, ItemIntoItemID = itemIntoItemID }); } db.Item.Add(i); db.SaveChanges(); status = "Adding " + i.Name + "..."; } catch (HttpRequestException httpRequestException) { Console.WriteLine(httpRequestException); status = "Scanning database..."; } return(status); } }