public IEnumerable <Project> GetFiltered(ProjectGetFilteredArgs arguments)
        {
            IQueryable <Project> query = _dbContext.Projects.Include(x => x.ProjectTasks);

            switch (arguments.ProjectsType)
            {
            case ProjectType.Done:
            {
                query = query.Where(x => x.State == "done");
                break;
            }

            case ProjectType.Deleted:
            {
                query = query.Where(x => x.State == "deleted");
                break;
            }

            case ProjectType.Active:
            {
                query = query.Where(x => x.State == "todo")
                        .Where(x => x.ExecutionTime != "someday");
                break;
            }

            case ProjectType.Disactive:
            {
                query = query.Where(x => x.ExecutionTime == "someday")
                        .Where(x => x.State != "todo");
                break;
            }

            default:
            {
                if (arguments.ProjectsType != ProjectType.All)
                {
                    throw new ArgumentException("Argument projectsType przyjął nieprawidłową wartość (wartość po której nie mogę przefiltrować danych)");
                }
                break;
            }
            }

            if (arguments.SearchPhrase != null)
            {
                query = query.Where(x =>
                                    x.Name.Contains(arguments.SearchPhrase) ||
                                    x.Description.Contains(arguments.SearchPhrase)
                                    );
            }

            try
            {
                return(query.ToList());
            }
            finally
            {
                _dbContext.Database.Connection.Close();
            }
        }
Ejemplo n.º 2
0
        public IEnumerable <T> GetFiltered <T>(ProjectGetFilteredArgs arguments) where T : ProjectBase
        {
            if (arguments == null)
            {
                throw new ArgumentNullException("Obiekt arguments musi mieć wartość różną od null");
            }

            var projects    = _projectsRepository.GetFiltered(arguments);
            var projectDtos = Mapper.Map <IEnumerable <T> >(projects);

            return(projectDtos);
        }