Exemple #1
0
        public IActionResult Get([FromQuery] GroupQueryDto query)
        {
            var userId = ClaimsReader.GetUserId(Request);

            if (!context.UserGroups.Any(a => a.GroupId == query.GroupId && a.UserId == userId && (a.Relation == GroupRelation.Owner || a.Relation == GroupRelation.User)))
            {
                return(BadRequest());
            }

            var result = context.Posts
                         .Where(a => a.GroupId == query.GroupId)
                         .OrderByDescending(a => a.DateAdded)
                         .ThenBy(a => a.DateAdded)
                         .Skip(query.PageSize * (query.Page - 1))
                         .Take(query.PageSize)
                         .Select(a => new PostDto
            {
                Id        = a.Id,
                DateAdded = a.DateAdded,
                Content   = a.Content,
                EditDate  = a.EditDate,
                IsOwner   = a.UserId == userId,
                Owner     = a.User.Login,
                Comments  = a.Comments.OrderBy(b => b.DateAdded).Select(b => new CommentDto
                {
                    Id        = b.Id,
                    DateAdded = b.DateAdded,
                    Content   = b.Content,
                    IsOwner   = b.UserId == userId,
                    Owner     = b.User.Login
                }).ToList()
            }).ToList();

            return(Ok(result));
        }
Exemple #2
0
        protected internal virtual CountResultDto getGroupCount(GroupQueryDto queryDto)
        {
            GroupQuery query = queryDto.toQuery(ProcessEngine);
            long       count = query.count();

            return(new CountResultDto(count));
        }
Exemple #3
0
        public virtual IList <GroupDto> queryGroups(GroupQueryDto queryDto, int?firstResult, int?maxResults)
        {
            queryDto.ObjectMapper = ObjectMapper;
            GroupQuery query = queryDto.toQuery(ProcessEngine);

            IList <Group> resultList;

            if (firstResult != null || maxResults != null)
            {
                resultList = executePaginatedQuery(query, firstResult, maxResults);
            }
            else
            {
                resultList = query.list();
            }

            return(GroupDto.fromGroupList(resultList));
        }
Exemple #4
0
        public ActionResult <IEnumerable <FileDto> > GetFiles([FromQuery] GroupQueryDto query)
        {
            var userId          = ClaimsReader.GetUserId(Request);
            var formattedFilter = string.IsNullOrEmpty(query.Filter) ? string.Empty : query.Filter.ToLower();

            var result = context.Set <DBFile>()
                         .Include(a => a.User)
                         .OrderByDescending(a => a.DateAdded)
                         .Where(a => a.GroupId == query.GroupId)
                         .Skip(query.PageSize * (query.Page - 1))
                         .Take(query.PageSize)
                         .Select(a => new FileDto
            {
                Id        = a.Id,
                Owner     = a.User.Login,
                DateAdded = a.DateAdded,
                FileName  = a.FileName,
                IsOwner   = a.UserId == userId,
                Size      = a.Size
            }).ToList();

            return(Ok(result));
        }
Exemple #5
0
        public IActionResult Get([FromQuery] GroupQueryDto query)
        {
            var userId = ClaimsReader.GetUserId(Request);

            if (!context.UserGroups.Any(a => a.GroupId == query.GroupId && a.UserId == userId && (a.Relation == GroupRelation.Owner || a.Relation == GroupRelation.User)))
            {
                return(BadRequest());
            }

            var result = context.Messages
                         .Where(a => a.GroupId == query.GroupId)
                         .OrderByDescending(a => a.DateAdded)
                         .Skip(query.PageSize * (query.Page - 1))
                         .Take(query.PageSize)
                         .Select(a => new MessageDto
            {
                DateAdded = a.DateAdded,
                Content   = a.Content,
                Owner     = a.Sender.Login
            }).ToList();

            return(Ok(result));
        }
Exemple #6
0
        public virtual CountResultDto getGroupCount(UriInfo uriInfo)
        {
            GroupQueryDto queryDto = new GroupQueryDto(ObjectMapper, uriInfo.QueryParameters);

            return(getGroupCount(queryDto));
        }
Exemple #7
0
        public virtual IList <GroupDto> queryGroups(UriInfo uriInfo, int?firstResult, int?maxResults)
        {
            GroupQueryDto queryDto = new GroupQueryDto(ObjectMapper, uriInfo.QueryParameters);

            return(queryGroups(queryDto, firstResult, maxResults));
        }
 /// <inheritdoc/>
 public IList <Group> QueryGroup(GroupQueryDto dto)
 {
     return(_groupQueryService.Query(dto.Query, dto.Sort, dto));
 }