/// <summary> /// Gets a list of art by selected list items. Returns a List<Art>. /// </summary> /// <param name="db"></param> /// <param name="selects"></param> /// <returns></returns> public static List <Art> GetArtsBySelectListItems(ArtDb db, IEnumerable <SelectListItem> selects) { List <string> names = (List <string>)selects.Select(a => a.Text); List <Art> arts = (List <Art>)db.DbArt.Where(a => names.Contains(a.Name)); return(arts); }
/// <summary> /// Gets all sculptures from Art db and sorts them into a key value pair by date. /// </summary> /// <param name="db"></param> /// <returns></returns> public static IDictionary <DateTime, IEnumerable <Art> > GetAllSculpturesMap(ArtDb db) { IEnumerable <Art> sculptures = db.DbArt.OrderByDescending(e => e.Date) .Where(p => p.Type == Medium.SCULPTURE); IDictionary <DateTime, IEnumerable <Art> > set = new Dictionary <DateTime, IEnumerable <Art> >(); DateTime date = new DateTime(); foreach (var sculpture in sculptures) { if (sculpture.Date.Year != date.Year) { List <Art> sculpt = new List <Art>(); IEnumerable <Art> art = new List <Art>(); sculpt.Add(sculpture); art = sculpt; set.Add(sculpture.Date, art); date = sculpture.Date; } else { IEnumerable <Art> art = set[date]; List <Art> sculpt = (List <Art>)art; sculpt.Add(sculpture); art = sculpt; set[date] = art; } } return(set); }
/// <summary> /// Gets all paintings from Art db and sorts them into a key value pair by date. /// </summary> /// <param name="db"></param> /// <returns></returns> public static IDictionary <DateTime, IEnumerable <Art> > GetAllPaintingsMap(ArtDb db) { IEnumerable <Art> paintings = db.DbArt.OrderByDescending(e => e.Date) .Where(p => p.Type == Medium.PAINTING); IDictionary <DateTime, IEnumerable <Art> > set = new Dictionary <DateTime, IEnumerable <Art> >(); DateTime date = new DateTime(); foreach (var painting in paintings) { if (painting.Date.Year != date.Year) { List <Art> paint = new List <Art>(); IEnumerable <Art> art = new List <Art>(); paint.Add(painting); art = paint; set.Add(painting.Date, art); date = painting.Date; } else { IEnumerable <Art> art = set[date]; List <Art> paint = (List <Art>)art; paint.Add(painting); art = paint; set[date] = art; } } return(set); }
/// <summary> /// Fills an Exhibit with an art gallery. /// </summary> /// <param name="db"></param> /// <param name="exhibit"></param> /// <returns></returns> public static Exhibit FillExhibit(ArtDb db, Exhibit exhibit) { if (exhibit != null) { exhibit.Gallery = ArtsDb.GetArtsByString(db, exhibit.ArtKeys); } return(exhibit); }
/// <summary> /// Gets a list of art by date with matching date and type. /// </summary> /// <param name="art"></param> /// <returns></returns> public static IEnumerable <Art> GetArtsByDate(ArtDb db, Art art) { int date = art.Date.Year; Medium type = art.Type; IEnumerable <Art> arts = db.DbArt.Where(a => a.Date.Year == date) .Where(a => a.Type == type); return(arts); }
/// <summary> /// Fills a list of Exhibit with an art gallery. /// </summary> /// <param name="db"></param> /// <param name="exhibits"></param> /// <returns></returns> public static IEnumerable <Exhibit> FillExhibits(ArtDb db, IEnumerable <Exhibit> exhibits) { foreach (var item in exhibits) { item.Gallery = ArtsDb.GetArtsByString(db, item.ArtKeys); } return(exhibits); }
/// <summary> /// Returns latest Exhibit by date. /// </summary> /// <param name="db"></param> /// <returns></returns> public static Exhibit GetNews(ArtDb db) { Exhibit ex = db.DbExhibit.OrderByDescending(e => e.Date).FirstOrDefault(); if (ex != null) { return(FillExhibit(db, ex)); } return(null); }
public static bool HasExhibit(ArtDb db, string name) { Exhibit ex = db.DbExhibit.Find(name); if (ex is null) { return(false); } return(true); }
/// <summary> /// Gets a list of art by name that match the date and type. /// </summary> /// <param name="art"></param> /// <returns></returns> public static IEnumerable <Art> GetArtsByName(ArtDb db, string name) { Art art = db.DbArt.Find(name); int date = art.Date.Year; Medium type = art.Type; IEnumerable <Art> arts = db.DbArt.OrderByDescending(e => e.Date) .Where(a => a.Date.Year == date) .Where(a => a.Type == type); return(arts); }
/// <summary> /// Gets a key-value pair of each Exhibit date and name in descending order. /// </summary> /// <param name="db"></param> /// <returns></returns> public static IDictionary <DateTime, string> GetExhibitMap(ArtDb db) { IEnumerable <Exhibit> exhibits = db.DbExhibit.OrderByDescending(e => e.Date).ToList(); IDictionary <DateTime, string> pair = new Dictionary <DateTime, string>(); foreach (var ex in exhibits) { pair.Add(ex.Date, ex.Name); } return(pair); }
/// <summary> /// Gets a list of art by current year starting alphabetically. /// Returns a List<SelectListItem> for ListBox in view. /// </summary> /// <param name="db"></param> /// <returns></returns> public static List <SelectListItem> GetCurrentArts_SelectListItems(ArtDb db) { List <SelectListItem> items = new List <SelectListItem>(); IEnumerable <Art> arts = db.DbArt.OrderBy(a => a.Name); foreach (var piece in arts) { items.Add(new SelectListItem { Text = piece.Name }); } return(items); }
/// <summary> /// Gets a list of art by comma-separated string items. Returns a List<Art>. /// </summary> /// <param name="db"></param> /// <param name="selects"></param> /// <returns></returns> public static IList <Art> GetArtsByString(ArtDb db, string selects) { IList <Art> arts = new List <Art>(); if (selects != null) { string[] names = selects.Split(','); IEnumerable <Art> iArts = db.DbArt.Where(a => names.Contains(a.Name)); IList <Art> artset = new List <Art>(iArts); arts = artset; } return(arts); }
/// <summary> /// Gets all painting dates from Art db and sorts them into a key value pair by date. /// </summary> /// <param name="db"></param> /// <returns></returns> public static IDictionary <DateTime, Medium> GetPaintingMap(ArtDb db) { IEnumerable <Art> paintings = db.DbArt.OrderByDescending(e => e.Date) .Where(p => p.Type == Medium.PAINTING); IDictionary <DateTime, Medium> set = new Dictionary <DateTime, Medium>(); DateTime date = new DateTime(); foreach (var painting in paintings) { if (painting.Date.Year != date.Year) { set.Add(painting.Date, Medium.PAINTING); date = painting.Date; } } return(set); }
/// <summary> /// Gets all sculpture dates from Art db and sorts them into a key value pair by date. /// </summary> /// <param name="db"></param> /// <returns></returns> public static IDictionary <DateTime, Medium> GetSculptureMap(ArtDb db) { IEnumerable <Art> sculptures = db.DbArt.OrderByDescending(e => e.Date) .Where(p => p.Type == Medium.SCULPTURE); IDictionary <DateTime, Medium> set = new Dictionary <DateTime, Medium>(); DateTime date = new DateTime(); foreach (var sculpt in sculptures) { if (sculpt.Date.Year != date.Year) { set.Add(sculpt.Date, Medium.SCULPTURE); date = sculpt.Date; } } return(set); }
/// <summary> /// Gets all paintings from Art db and sorts them into a list. /// </summary> /// <param name="db"></param> /// <returns></returns> public static IEnumerable <Art> GetAllPaintings(ArtDb db) { return(db.DbArt.OrderByDescending(e => e.Date).Where(p => p.Type == Medium.PAINTING)); }
public static void DeleteExhibit(ArtDb db, Exhibit exhibit) { db.DbExhibit.Remove(exhibit); db.SaveChanges(); }
public static void UpdateArt(ArtDb db, Art art) { db.Entry(art).State = EntityState.Modified; db.SaveChanges(); }
public static void DeleteArt(ArtDb db, Art art) { db.DbArt.Remove(art); db.SaveChanges(); }
/// <summary> /// Gets specific Art by name. /// </summary> /// <param name="db"></param> /// <param name="name"></param> /// <returns></returns> public static Art GetArt(ArtDb db, string name) { return(db.DbArt.Find(name)); }
public static void AddArts(ArtDb db, IEnumerable <Art> arts) { db.DbArt.AddRange(arts); }
/// <summary> /// Exhibits are ordered in descending order, enabling first element /// access to latest Exhibit by date. First element is news. /// </summary> /// <param name="db"></param> /// <returns></returns> public static IEnumerable <Exhibit> GetAllExhibits(ArtDb db) { IEnumerable <Exhibit> ex = db.DbExhibit.OrderByDescending(e => e.Date).ToList(); return(FillExhibits(db, ex)); }
/// <summary> /// Gets Exhibit by name. /// </summary> /// <param name="db"></param> /// <param name="name"></param> /// <returns></returns> public static Exhibit GetExhibit(ArtDb db, string name) { Exhibit ex = db.DbExhibit.Find(name); return(FillExhibit(db, ex)); }
/// <summary> /// Gets all sculptures from Art db and sorts them into a list. /// </summary> /// <param name="db"></param> /// <returns></returns> public static IEnumerable <Art> GetAllSculptures(ArtDb db) { return(db.DbArt.OrderByDescending(e => e.Date).Where(p => p.Type == Medium.SCULPTURE)); }
/// <summary> /// Get all Art starting with most recent at index 0. /// </summary> /// <param name="db"></param> /// <returns></returns> public static IEnumerable <Art> GetAllArts(ArtDb db) { return(db.DbArt.OrderByDescending(e => e.Date).ToList()); }
public static void AddExhibits(ArtDb db, IEnumerable <Exhibit> exhibits) { db.DbExhibit.AddRange(exhibits); }