protected virtual void Dispose(bool disposing) { if (disposing) { // dispose the DbContext _context.Dispose(); _context = null; } }
/// <summary> /// update database with localized quests information /// </summary> /// <param name="quests">quests with information to update</param> /// <param name="culture">culture for localization</param> /// <returns>updated quests from database</returns> public IEnumerable <Quest> UpdateQuests(IEnumerable <Quest> quests, CultureInfo culture) { using (MangosEntities context = GetContext()) { var quest_templates = quests.Join(context.quest_template, o => o.Id, o => o.entry, (i, it) => new { it, i }); var locales_quests = quests.Join(context.locales_quest, o => o.Id, o => o.entry, (i, li) => new { li, i }); switch (LocalizationHelper.GetOffset(culture)) { case 0: quest_templates.ToList().ForEach(o => { o.it.Title = o.i.Title; o.it.Details = o.i.Details; o.it.Objectives = o.i.Objectives; o.it.OfferRewardText = o.i.OfferRewardText; o.it.RequestItemsText = o.i.RequestItemsText; o.it.EndText = o.i.EndText; o.it.CompletedText = o.i.CompletedText; o.it.ObjectiveText1 = o.i.ObjectiveText1; o.it.ObjectiveText2 = o.i.ObjectiveText2; o.it.ObjectiveText3 = o.i.ObjectiveText3; o.it.ObjectiveText4 = o.i.ObjectiveText4; }); break; case 1: locales_quests.ToList().ForEach(o => { o.li.Title_loc1 = o.i.Title; o.li.Details_loc1 = o.i.Details; o.li.Objectives_loc1 = o.i.Objectives; o.li.OfferRewardText_loc1 = o.i.OfferRewardText; o.li.RequestItemsText_loc1 = o.i.RequestItemsText; o.li.EndText_loc1 = o.i.EndText; o.li.CompletedText_loc1 = o.i.CompletedText; o.li.ObjectiveText1_loc1 = o.i.ObjectiveText1; o.li.ObjectiveText2_loc1 = o.i.ObjectiveText2; o.li.ObjectiveText3_loc1 = o.i.ObjectiveText3; o.li.ObjectiveText4_loc1 = o.i.ObjectiveText4; }); break; case 2: locales_quests.ToList().ForEach(o => { o.li.Title_loc2 = o.i.Title; o.li.Details_loc2 = o.i.Details; o.li.Objectives_loc2 = o.i.Objectives; o.li.OfferRewardText_loc2 = o.i.OfferRewardText; o.li.RequestItemsText_loc2 = o.i.RequestItemsText; o.li.EndText_loc2 = o.i.EndText; o.li.CompletedText_loc2 = o.i.CompletedText; o.li.ObjectiveText1_loc2 = o.i.ObjectiveText1; o.li.ObjectiveText2_loc2 = o.i.ObjectiveText2; o.li.ObjectiveText3_loc2 = o.i.ObjectiveText3; o.li.ObjectiveText4_loc2 = o.i.ObjectiveText4; }); break; case 3: locales_quests.ToList().ForEach(o => { o.li.Title_loc3 = o.i.Title; o.li.Details_loc3 = o.i.Details; o.li.Objectives_loc3 = o.i.Objectives; o.li.OfferRewardText_loc3 = o.i.OfferRewardText; o.li.RequestItemsText_loc3 = o.i.RequestItemsText; o.li.EndText_loc3 = o.i.EndText; o.li.CompletedText_loc3 = o.i.CompletedText; o.li.ObjectiveText1_loc3 = o.i.ObjectiveText1; o.li.ObjectiveText2_loc3 = o.i.ObjectiveText2; o.li.ObjectiveText3_loc3 = o.i.ObjectiveText3; o.li.ObjectiveText4_loc3 = o.i.ObjectiveText4; }); break; case 4: locales_quests.ToList().ForEach(o => { o.li.Title_loc4 = o.i.Title; o.li.Details_loc4 = o.i.Details; o.li.Objectives_loc4 = o.i.Objectives; o.li.OfferRewardText_loc4 = o.i.OfferRewardText; o.li.RequestItemsText_loc4 = o.i.RequestItemsText; o.li.EndText_loc4 = o.i.EndText; o.li.CompletedText_loc4 = o.i.CompletedText; o.li.ObjectiveText1_loc4 = o.i.ObjectiveText1; o.li.ObjectiveText2_loc4 = o.i.ObjectiveText2; o.li.ObjectiveText3_loc4 = o.i.ObjectiveText3; o.li.ObjectiveText4_loc4 = o.i.ObjectiveText4; }); break; case 5: locales_quests.ToList().ForEach(o => { o.li.Title_loc5 = o.i.Title; o.li.Details_loc5 = o.i.Details; o.li.Objectives_loc5 = o.i.Objectives; o.li.OfferRewardText_loc5 = o.i.OfferRewardText; o.li.RequestItemsText_loc5 = o.i.RequestItemsText; o.li.EndText_loc5 = o.i.EndText; o.li.CompletedText_loc5 = o.i.CompletedText; o.li.ObjectiveText1_loc5 = o.i.ObjectiveText1; o.li.ObjectiveText2_loc5 = o.i.ObjectiveText2; o.li.ObjectiveText3_loc5 = o.i.ObjectiveText3; o.li.ObjectiveText4_loc5 = o.i.ObjectiveText4; }); break; case 6: locales_quests.ToList().ForEach(o => { o.li.Title_loc6 = o.i.Title; o.li.Details_loc6 = o.i.Details; o.li.Objectives_loc6 = o.i.Objectives; o.li.OfferRewardText_loc6 = o.i.OfferRewardText; o.li.RequestItemsText_loc6 = o.i.RequestItemsText; o.li.EndText_loc6 = o.i.EndText; o.li.CompletedText_loc6 = o.i.CompletedText; o.li.ObjectiveText1_loc6 = o.i.ObjectiveText1; o.li.ObjectiveText2_loc6 = o.i.ObjectiveText2; o.li.ObjectiveText3_loc6 = o.i.ObjectiveText3; o.li.ObjectiveText4_loc6 = o.i.ObjectiveText4; }); break; case 7: locales_quests.ToList().ForEach(o => { o.li.Title_loc7 = o.i.Title; o.li.Details_loc7 = o.i.Details; o.li.Objectives_loc7 = o.i.Objectives; o.li.OfferRewardText_loc7 = o.i.OfferRewardText; o.li.RequestItemsText_loc7 = o.i.RequestItemsText; o.li.EndText_loc7 = o.i.EndText; o.li.CompletedText_loc7 = o.i.CompletedText; o.li.ObjectiveText1_loc7 = o.i.ObjectiveText1; o.li.ObjectiveText2_loc7 = o.i.ObjectiveText2; o.li.ObjectiveText3_loc7 = o.i.ObjectiveText3; o.li.ObjectiveText4_loc7 = o.i.ObjectiveText4; }); break; case 8: locales_quests.ToList().ForEach(o => { o.li.Title_loc8 = o.i.Title; o.li.Details_loc8 = o.i.Details; o.li.Objectives_loc8 = o.i.Objectives; o.li.OfferRewardText_loc8 = o.i.OfferRewardText; o.li.RequestItemsText_loc8 = o.i.RequestItemsText; o.li.EndText_loc8 = o.i.EndText; o.li.CompletedText_loc8 = o.i.CompletedText; o.li.ObjectiveText1_loc8 = o.i.ObjectiveText1; o.li.ObjectiveText2_loc8 = o.i.ObjectiveText2; o.li.ObjectiveText3_loc8 = o.i.ObjectiveText3; o.li.ObjectiveText4_loc8 = o.i.ObjectiveText4; }); break; default: throw new NotImplementedException("Unsupported culture " + culture.Name); } context.SaveChanges(); } List <int> ids = quests.Select(o => o.Id).ToList(); var updatedQuests = _context.quest_template.Where(o => ids.Contains(o.entry)); return(GetQuests(updatedQuests, culture)); }
/// <summary> /// update database with localized items information /// </summary> /// <param name="items">items with information to update</param> /// <param name="culture">culture for localization</param> /// <returns>updated items from database</returns> public IEnumerable <Item> UpdateItems(IEnumerable <Item> items, CultureInfo culture) { using (MangosEntities context = GetContext()) { var item_templates = items.Join(context.item_template, o => o.Id, o => o.entry, (i, it) => new { it, i }); var locales_items = items.Join(context.locales_item, o => o.Id, o => o.entry, (i, li) => new { li, i }); switch (LocalizationHelper.GetOffset(culture)) { case 0: item_templates.ToList().ForEach(o => { o.it.name = o.i.Name; o.it.description = o.i.Description; }); break; case 1: locales_items.ToList().ForEach(o => { o.li.name_loc1 = o.i.Name; o.li.description_loc1 = o.i.Description; }); break; case 2: locales_items.ToList().ForEach(o => { o.li.name_loc2 = o.i.Name; o.li.description_loc2 = o.i.Description; }); break; case 3: locales_items.ToList().ForEach(o => { o.li.name_loc3 = o.i.Name; o.li.description_loc3 = o.i.Description; }); break; case 4: locales_items.ToList().ForEach(o => { o.li.name_loc4 = o.i.Name; o.li.description_loc4 = o.i.Description; }); break; case 5: locales_items.ToList().ForEach(o => { o.li.name_loc5 = o.i.Name; o.li.description_loc5 = o.i.Description; }); break; case 6: locales_items.ToList().ForEach(o => { o.li.name_loc6 = o.i.Name; o.li.description_loc6 = o.i.Description; }); break; case 7: locales_items.ToList().ForEach(o => { o.li.name_loc7 = o.i.Name; o.li.description_loc7 = o.i.Description; }); break; case 8: locales_items.ToList().ForEach(o => { o.li.name_loc8 = o.i.Name; o.li.description_loc8 = o.i.Description; }); break; default: throw new NotImplementedException("Unsupported culture " + culture.Name); } context.SaveChanges(); } List <int> ids = items.Select(o => o.Id).ToList(); var updatedItems = _context.item_template.Where(o => ids.Contains(o.entry)); return(GetItems(updatedItems, culture)); }
public MangosProvider() { _context = GetContext(); }