Beispiel #1
0
        private bool CheckEmptyCriteria(VideoSearchCriteria criteria)
        {
            bool isEmpty = false;

            if (criteria.TitleBlank() && criteria.DirectorBlank() && !criteria.YearIsPostive())
            {
                isEmpty = true;
            }

            return(isEmpty);
        }
Beispiel #2
0
        public Collection <VideoSearchResult> SearchVideoLibrary(VideoSearchCriteria criteria)
        {
            string tsql = string.Empty;

            if (CheckEmptyCriteria(criteria))
            {
                tsql = "SELECT * FROM dbo.Videos Where IsDeleted <> 1";
            }

            else if (criteria.HasOneSearchCriteria())
            {
                if (criteria.HasTitle)
                {
                    tsql = $"SELECT * FROM dbo.Videos Where IsDeleted <> 1 and Title Like '%{criteria.Title}%'";
                }
                else if (criteria.HasDirector)
                {
                    tsql = $"SELECT * FROM dbo.Videos Where IsDeleted <> 1 and Director Like '%{criteria.Director}%'";
                }
                else
                {
                    tsql = $"SELECT * FROM dbo.Videos Where IsDeleted <> 1 and Year = {criteria.Year}";
                }
            }

            else
            {
                if (criteria.TitleBlank())
                {
                    tsql = $"SELECT * FROM dbo.Videos Where IsDeleted <> 1 and Director Like '%{criteria.Director}%' and Year = {criteria.Year}";
                }
                else if (criteria.DirectorBlank())
                {
                    tsql = $"SELECT * FROM dbo.Videos Where IsDeleted <> 1 and Title Like '%{criteria.Title}%' and Year = {criteria.Year} ";
                }
                else if (!criteria.YearIsPostive())
                {
                    tsql = $"SELECT * FROM dbo.Videos Where IsDeleted <> 1 and Director Like '%{criteria.Director}%' and Title Like '%{criteria.Title}%'";
                }
                else
                {
                    tsql = $"SELECT * FROM dbo.Videos Where IsDeleted <> 1 and Director Like '%{criteria.Director}%' and Title Like '%{criteria.Title}%' and Year = {criteria.Year}";
                }
            }

            var temp = db.ExecuteSqlStringAccessor <VideoSearchResult>(tsql);
            Collection <VideoSearchResult> result = new Collection <VideoSearchResult>(temp.ToList());

            return(result);
        }
        public Collection <VideoSearchResult> SearchVideoLibrary(VideoSearchCriteria criteria)
        {
            var results = new Collection <VideoSearchResult>();

            using (var context = new VideoLibraryDLEFImplementation.VideoLibrary())
            {
                IQueryable <Video> query;

                if (CheckEmptyCriteria(criteria))
                {
                    query = from v in context.Videos
                            where !v.IsDeleted
                            select v;
                }

                else if (criteria.HasOneSearchCriteria())
                {
                    if (criteria.HasTitle)
                    {
                        query = from v in context.Videos
                                where !v.IsDeleted && v.Title.Contains(criteria.Title)
                                select v;
                    }
                    else if (criteria.HasDirector)
                    {
                        query = from v in context.Videos
                                where !v.IsDeleted && v.Director.Contains(criteria.Director)
                                select v;
                    }
                    else
                    {
                        query = from v in context.Videos
                                where !v.IsDeleted && v.Year == criteria.Year
                                select v;
                    }
                }
                else
                {
                    if (criteria.TitleBlank())
                    {
                        query = from v in context.Videos
                                where !v.IsDeleted && v.Director.Contains(criteria.Director) && v.Year == criteria.Year
                                select v;
                    }
                    else if (criteria.DirectorBlank())
                    {
                        query = from v in context.Videos
                                where !v.IsDeleted && v.Title.Contains(criteria.Title) && v.Year == criteria.Year
                                select v;
                    }
                    else if (!criteria.YearIsPostive())
                    {
                        query = from v in context.Videos
                                where !v.IsDeleted && v.Title.Contains(criteria.Title) && v.Director.Contains(criteria.Director)
                                select v;
                    }
                    else
                    {
                        query = from v in context.Videos
                                where !v.IsDeleted && v.Title.Contains(criteria.Title) && v.Director.Contains(criteria.Director) && v.Year == criteria.Year
                                select v;
                    }
                }

                foreach (var video in query)
                {
                    VideoSearchResult result = new VideoSearchResult(video.VideoId, video.Title, video.Year, video.Director);
                    results.Add(result);
                }
            }
            return(results);
        }