Esempio n. 1
0
        public IEnumerable <T> GetFiltered <T>(TaskGetFilteredArgs arguments) where T : TaskBase
        {
            if (arguments == null)
            {
                throw new ArgumentNullException("Obiekt arguments musi mieć wartość różną od null");
            }

            var tasks    = _tasksRepository.GetFiltered(arguments);
            var taskDtos = Mapper.Map <IEnumerable <T> >(tasks);

            return(taskDtos);
        }
Esempio n. 2
0
        public IEnumerable <Task> GetFiltered(TaskGetFilteredArgs arguments)
        {
            IQueryable <Task> query = _dbContext.Tasks;

            if (arguments.ProjectID != null)
            {
                query = query.Where(x => x.ProjectID == arguments.ProjectID);
            }

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

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

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

            case TaskType.Disactive:
            {
                query = query.Where(x => x.ProjectID == null)
                        .Where(x => x.ExecutionTime == "someday");
                break;
            }

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

            if (arguments.TimeType != null)
            {
                query = query.Where(x => x.ExecutionTime == arguments.TimeType);
            }

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

            if (arguments.Date != null)
            {
                query = query.Where(x => x.StartTime == arguments.Date);
            }

            try
            {
                return(query.ToList());
            }
            finally
            {
                _dbContext.Database.Connection.Close();
            }
        }