public async Task SaveAll(List <League> leagues) { using var context = new SidekickContext(options); context.Leagues.RemoveRange(await FindAll()); context.AddRange(leagues); await context.SaveChangesAsync(); }
public static void Initialize(SidekickContext context) { context.Database.EnsureCreated(); InitializeConditionCodes(context); InitializeStateCodes(context); }
// Initialize the data in the ConditionCodes table. // The set of condition codes came from: https://www.mycomicshop.com/help/grading // I chose the simplere basic grading scale. This is something I would normally discuss with the client. private static void InitializeConditionCodes(SidekickContext context) { if (!context.ConditionCodes.Any()) { var conditionCodes = new ConditionCode[] { new ConditionCode { Name = "NM Near Mint" }, new ConditionCode { Name = "VF Very Fine" }, new ConditionCode { Name = "FN Fine" }, new ConditionCode { Name = "VG Very Good" }, new ConditionCode { Name = "GD Good" }, new ConditionCode { Name = "FR Fair" }, new ConditionCode { Name = "PR Poor" } }; foreach (ConditionCode conditionCode in conditionCodes) { context.ConditionCodes.Add(conditionCode); } context.SaveChanges(); } }
public async Task <Window> Get(string id) { using var dbContext = new SidekickContext(options); logger.Debug($"WindowService : Getting data for {id}"); return(await dbContext.Windows.FindAsync(id)); }
public async Task <ItemCategory> Get(string type) { logger.Debug($"ItemCategoryService : Getting data for {type}"); using var dbContext = new SidekickContext(options); return(await dbContext.ItemCategories.FindAsync(type)); }
private async Task <TModel> Get <TModel>(string key) where TModel : class { using var context = new SidekickContext(options); var cache = await context.Caches.FindAsync(key); if (string.IsNullOrEmpty(cache?.Data)) { return(default);
public async Task <TModel> Get <TModel>(string key) where TModel : class { logger.Debug($"CacheService : Getting data for {key}"); using var dbContext = new SidekickContext(options); var cache = await dbContext.Caches.FindAsync(key); if (string.IsNullOrEmpty(cache?.Data)) { return(default);
public async Task Delete(string type) { using var dbContext = new SidekickContext(options); var itemCategory = await dbContext.ItemCategories.FindAsync(type); if (itemCategory != null) { dbContext.ItemCategories.Remove(itemCategory); await dbContext.SaveChangesAsync(); } }
public async Task <NinjaPrice> Find(string name, bool corrupted, int mapTier, int gemLevel) { using var dbContext = new SidekickContext(options); var translation = await dbContext.NinjaTranslations.FirstOrDefaultAsync(x => x.Translation == name); if (translation != null) { name = translation.English; } return(await dbContext.NinjaPrices.FirstOrDefaultAsync(x => x.Name == name && x.Corrupted == corrupted && x.MapTier == mapTier && x.GemLevel == gemLevel)); }
public async Task Clear() { using var dbContext = new SidekickContext(options); var prices = await dbContext.NinjaPrices.ToListAsync(); dbContext.NinjaPrices.RemoveRange(prices); var translations = await dbContext.NinjaTranslations.ToListAsync(); dbContext.NinjaTranslations.RemoveRange(translations); await dbContext.SaveChangesAsync(); }
public async Task <TModel> GetOrSet <TModel>(string key, Func <Task <TModel> > func) where TModel : class { using var context = new SidekickContext(options); var result = await Get <TModel>(key); if (result == default) { result = await func.Invoke(); await Save(key, result); } return(result); }
public async Task Delete(string type) { logger.Debug($"ItemCategoryService : Deleting data for {type}"); using var dbContext = new SidekickContext(options); var itemCategory = await dbContext.ItemCategories.FindAsync(type); if (itemCategory != null) { dbContext.ItemCategories.Remove(itemCategory); await dbContext.SaveChangesAsync(); } }
public async Task SaveCategory(string type, string category) { using var dbContext = new SidekickContext(options); var itemCategory = await dbContext.ItemCategories.FindAsync(type); if (itemCategory == null) { itemCategory = new ItemCategory() { Type = type, }; dbContext.ItemCategories.Add(itemCategory); } itemCategory.Category = category; await dbContext.SaveChangesAsync(); }
public async Task SaveSize(View id, int width, int height) { using var context = new SidekickContext(options); var preference = await context.ViewPreferences.FindAsync(id); if (preference == null) { preference = new ViewPreference() { Id = id, }; context.ViewPreferences.Add(preference); } preference.Height = height; preference.Width = width; await context.SaveChangesAsync(); }
public async Task SavePrices(List <NinjaPrice> prices) { using var dbContext = new SidekickContext(options); prices = prices .GroupBy(x => (x.Name, x.Corrupted, x.MapTier, x.GemLevel)) .Select(x => x.OrderBy(x => x.Price).First()) .ToList(); var names = prices.Select(x => x.Name); var data = await dbContext.NinjaPrices .Where(x => names.Any(y => y == x.Name)) .ToListAsync(); dbContext.NinjaPrices.RemoveRange(data); await dbContext.SaveChangesAsync(); dbContext.NinjaPrices.AddRange(prices); await dbContext.SaveChangesAsync(); }
public async Task SaveTranslations(List <NinjaTranslation> translations) { using var dbContext = new SidekickContext(options); translations = translations .GroupBy(x => x.English) .Select(x => x.First()) .ToList(); var names = translations.Select(x => x.English); var data = await dbContext.NinjaTranslations .Where(x => names.Any(y => y == x.English)) .ToListAsync(); dbContext.NinjaTranslations.RemoveRange(data); await dbContext.SaveChangesAsync(); dbContext.NinjaTranslations.AddRange(translations); await dbContext.SaveChangesAsync(); }
public async Task SaveCategory(string type, string category) { logger.Debug($"ItemCategoryService : Saving data for {type}"); using var dbContext = new SidekickContext(options); var itemCategory = await dbContext.ItemCategories.FindAsync(type); if (itemCategory == null) { itemCategory = new ItemCategory() { Type = type, }; dbContext.ItemCategories.Add(itemCategory); } itemCategory.Category = category; await dbContext.SaveChangesAsync(); }
public async Task SaveSize(string id, double width, double height) { using var dbContext = new SidekickContext(options); var window = await dbContext.Windows.FindAsync(id); if (window == null) { window = new Window() { Id = id, }; dbContext.Windows.Add(window); } window.Height = height; window.Width = width; await dbContext.SaveChangesAsync(); logger.Debug($"WindowService : Saved data for {id}. Width: {width}, Height: {height}"); }
public async Task <NinjaPrice> Find(Item item) { using var dbContext = new SidekickContext(options); var name = item.Original.Name; var type = item.Original.Type; var translation = await dbContext.NinjaTranslations.FirstOrDefaultAsync(x => x.Translation == name); if (translation != null) { name = translation.English; } var query = dbContext.NinjaPrices .Where(x => x.Name == name || x.Name == type); if (item.Properties != null) { query = query.Where(x => x.Corrupted == item.Properties.Corrupted && x.MapTier == item.Properties.MapTier && x.GemLevel == item.Properties.GemLevel); } return(await query.FirstOrDefaultAsync()); }
public ComicsController(SidekickContext context) { _context = context; }
public ConditionCodesController(SidekickContext context) { _context = context; }
public async Task <List <League> > FindAll() { using var context = new SidekickContext(options); return(await context.Leagues.ToListAsync()); }
// Initialize the data in the StateCodes table. // The set of state codes came from: https://abbreviations.yourdictionary.com/articles/state-abbrev.html private static void InitializeStateCodes(SidekickContext context) { if (!context.StateCode.Any()) { var stateCodes = new StateCode[] { new StateCode { Abbreviation = "AL", Name = "Alabama" }, new StateCode { Abbreviation = "AK", Name = "Alaska" }, new StateCode { Abbreviation = "AZ", Name = "Arizona" }, new StateCode { Abbreviation = "AR", Name = "Arkansas" }, new StateCode { Abbreviation = "CA", Name = "California" }, new StateCode { Abbreviation = "CO", Name = "Colorado" }, new StateCode { Abbreviation = "CT", Name = "Connecticut" }, new StateCode { Abbreviation = "DE", Name = "Delaware" }, new StateCode { Abbreviation = "FL", Name = "Florida" }, new StateCode { Abbreviation = "GA", Name = "Georgia" }, new StateCode { Abbreviation = "HI", Name = "Hawaii" }, new StateCode { Abbreviation = "ID", Name = "Idaho" }, new StateCode { Abbreviation = "IL", Name = "Illinois" }, new StateCode { Abbreviation = "IN", Name = "Indiana" }, new StateCode { Abbreviation = "IA", Name = "Iowa" }, new StateCode { Abbreviation = "KS", Name = "Kansas" }, new StateCode { Abbreviation = "KY", Name = "Kentucky" }, new StateCode { Abbreviation = "LA", Name = "Louisiana" }, new StateCode { Abbreviation = "ME", Name = "Maine" }, new StateCode { Abbreviation = "MD", Name = "Maryland" }, new StateCode { Abbreviation = "MA", Name = "Massachusetts" }, new StateCode { Abbreviation = "MI", Name = "Michigan" }, new StateCode { Abbreviation = "MN", Name = "Minnesota" }, new StateCode { Abbreviation = "MS", Name = "Mississippi" }, new StateCode { Abbreviation = "MO", Name = "Missouri" }, new StateCode { Abbreviation = "MT", Name = "Montana" }, new StateCode { Abbreviation = "NE", Name = "Nebraska" }, new StateCode { Abbreviation = "NV", Name = "Nevada" }, new StateCode { Abbreviation = "NH", Name = "New Hampshire" }, new StateCode { Abbreviation = "NJ", Name = "New Jersey" }, new StateCode { Abbreviation = "NM", Name = "New Mexico" }, new StateCode { Abbreviation = "NY", Name = "New York" }, new StateCode { Abbreviation = "NC", Name = "North Carolina" }, new StateCode { Abbreviation = "ND", Name = "North Dakota" }, new StateCode { Abbreviation = "OH", Name = "Ohio" }, new StateCode { Abbreviation = "OK", Name = "Oklahoma" }, new StateCode { Abbreviation = "OR", Name = "Oregon" }, new StateCode { Abbreviation = "PA", Name = "Pennsylvania" }, new StateCode { Abbreviation = "RI", Name = "Rhode Island" }, new StateCode { Abbreviation = "SC", Name = "South Carolina" }, new StateCode { Abbreviation = "SD", Name = "South Dakota" }, new StateCode { Abbreviation = "TN", Name = "Tennessee" }, new StateCode { Abbreviation = "TX", Name = "Texas" }, new StateCode { Abbreviation = "UT", Name = "Utah" }, new StateCode { Abbreviation = "VT", Name = "Vermont" }, new StateCode { Abbreviation = "VA", Name = "Virginia" }, new StateCode { Abbreviation = "WA", Name = "Washington" }, new StateCode { Abbreviation = "WV", Name = "West Virginia" }, new StateCode { Abbreviation = "WI", Name = "Wisconsin" }, new StateCode { Abbreviation = "WY", Name = "Wyoming" } }; foreach (StateCode stateCode in stateCodes) { context.StateCode.Add(stateCode); } context.SaveChanges(); } }
public async Task <ViewPreference> Get(View id) { using var context = new SidekickContext(options); return(await context.ViewPreferences.FindAsync(id)); }
public VendorsController(SidekickContext context) { _context = context; }
public async Task <ItemCategory> Get(string type) { using var dbContext = new SidekickContext(options); return(await dbContext.ItemCategories.FindAsync(type)); }
public StateCodesController(SidekickContext context) { _context = context; }