Ejemplo n.º 1
0
        public async Task <IActionResult> GetValidationState([FromQuery] string termId)
        {
            if (string.IsNullOrWhiteSpace(termId))
            {
                return(new BadRequestObjectResult("Brak semestru."));
            }

            var gradeStatus = !_thesisRepository.GetAll()
                              .Any(p => !p.Hidden && p.TermId == termId && string.IsNullOrWhiteSpace(p.Grade));

            return(new OkObjectResult(gradeStatus));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SearchTheses(
            [FromQuery] string terms,
            [FromQuery] string text,
            [FromQuery] string users,
            [FromQuery] string keywords,
            [FromQuery] bool noGrade,
            [FromQuery] int page,
            [FromQuery] int count)
        {
            var termIds     = terms?.Split(';').Distinct().ToList();
            var userIds     = users?.Split(';').Distinct().ToList();
            var keywordList = keywords?.Split(';').Distinct().ToList();

            var query = _thesisRepository.GetAll().Where(t => !t.Hidden);

            query = !noGrade ? query : query.Where(t => t.Grade == null);

            query = termIds == null ? query : query.Where(t => termIds.Contains(t.TermId));

            if (text != null)
            {
                query = query.Where(t =>
                                    t.Title.Contains(text, StringComparison.InvariantCultureIgnoreCase) ||
                                    t.Abstract.Contains(text, StringComparison.InvariantCultureIgnoreCase));
            }
            else if (userIds != null)
            {
                //ToList before where due to EF Core limitations
                query = query.ToList().Where(t =>
                                             userIds.Contains(t.Promoter.Id.ToString()) ||
                                             userIds.Contains(t.Reviewer.Id.ToString()) ||
                                             t.ThesisAuthors.Select(a => a.AuthorId.ToString()).Intersect(userIds).Any())
                        .AsQueryable();
            }
            else if (keywordList != null)
            {
                //ToList before where due to EF Core limitations
                query = query.ToList()
                        .Where(t => t.ThesisKeywords.Select(k => k.Keyword.Text).Intersect(keywordList).Count() == keywordList.Count)
                        .AsQueryable();
            }

            var result      = query.ToExtendedDto();
            var resultCount = result.Count;

            return(new OkObjectResult(new
            {
                theses = result.Skip(page * count).Take(count).ToList(),
                itemCount = resultCount
            }));
        }
Ejemplo n.º 3
0
        public async Task <bool> CanBeDeleted(Guid guid)
        {
            var file = await _fileRepository.GetAsync(guid);

            var thesisGuid = file.Thesis != null ? file.Thesis.Guid : file.ThesisAdditionalFiles.FirstOrDefault().Thesis.Guid;
            var isPromoter = _thesisService.IsPromoter(thesisGuid);

            if (!isPromoter && !_userContext.CurrentUser.IsAdmin)
            {
                return(false);
            }

            return(!_thesisRepository.GetAll().Any(t => t.FileId == file.Id));
        }
Ejemplo n.º 4
0
        private IQueryable <Thesis> GetThesesForUser(string termId)
        {
            var query = _thesisRepository.GetAll().Where(t => t.TermId == termId);

            if (!_userContext.CurrentUser.IsAdmin)
            {
                query.Where(t => !t.Hidden);
            }
            return(query);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> GetAllTerms()
        {
            var thesisTerms = _thesisRepository.GetAll().Select(t => t.TermId).Distinct().ToList();
            var terms       = new List <TermDTO>();

            if (thesisTerms.Count != 0)
            {
                var usosTerms = await _usosService.GetTerms(_userContext.GetCredentials());

                terms.AddRange(usosTerms.Where(t => thesisTerms.Contains(t.Id)).ToDto());
            }

            var currentTerm = await _usosService.GetCurrentAcademicYear();

            if (terms.FirstOrDefault(t => t.Id == currentTerm.Id) == null)
            {
                terms.Add(currentTerm.ToDto());
            }

            return(new OkObjectResult(terms));
        }