Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
 /// <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);
 }
Пример #5
0
        /// <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);
        }
Пример #6
0
 /// <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);
 }
Пример #7
0
        /// <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);
        }
Пример #8
0
        public static bool HasExhibit(ArtDb db, string name)
        {
            Exhibit ex = db.DbExhibit.Find(name);

            if (ex is null)
            {
                return(false);
            }
            return(true);
        }
Пример #9
0
        /// <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);
        }
Пример #10
0
        /// <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);
        }
Пример #11
0
        /// <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);
        }
Пример #12
0
        /// <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);
        }
Пример #13
0
        /// <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);
        }
Пример #14
0
        /// <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);
        }
Пример #15
0
 /// <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));
 }
Пример #16
0
 public static void DeleteExhibit(ArtDb db, Exhibit exhibit)
 {
     db.DbExhibit.Remove(exhibit);
     db.SaveChanges();
 }
Пример #17
0
 public static void UpdateArt(ArtDb db, Art art)
 {
     db.Entry(art).State = EntityState.Modified;
     db.SaveChanges();
 }
Пример #18
0
 public static void DeleteArt(ArtDb db, Art art)
 {
     db.DbArt.Remove(art);
     db.SaveChanges();
 }
Пример #19
0
 /// <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));
 }
Пример #20
0
 public static void AddArts(ArtDb db, IEnumerable <Art> arts)
 {
     db.DbArt.AddRange(arts);
 }
Пример #21
0
        /// <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));
        }
Пример #22
0
        /// <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));
        }
Пример #23
0
 /// <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));
 }
Пример #24
0
 /// <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());
 }
Пример #25
0
 public static void AddExhibits(ArtDb db, IEnumerable <Exhibit> exhibits)
 {
     db.DbExhibit.AddRange(exhibits);
 }