Beispiel #1
0
        public static CommentAsIsDTO ConvertToAsIs(this Comment model, IMapper _mapper)
        {
            CommentAsIsDTO dto = _mapper.Map <Comment, CommentAsIsDTO>(model);

            dto.Date        = model.DatePosted.ToShortDateString();
            dto.Time        = model.DatePosted.ToShortTimeString();
            dto.User        = model?.User?.Convert(_mapper);
            dto.Checks      = model.MyChecks?.Select(m => m.Convert <UserCheckList, UserCheckOnly>(_mapper)).ToList();
            dto.SubComments = _mapper.Map <ICollection <Comment>, ICollection <CommentAsIsDTO> >(model.SubComments).ToList();
            return(dto);
        }
        public async ValueTask <IActionResult> Get(int id, bool project = false)
        {
            Comment comment = null;

            if (!project)
            {
                comment = await _repo.Item()
                          .Where(c => c.Id == id)
                          .Include(c => c.MyChecks)
                          .Include(c => c.SubComments)
                          .FirstOrDefaultAsync();

                if (comment != null)
                {
                    BaseCommentWithCheck model = comment.ConvertToBaseWithUserCheck(_mapper);
                    return(Ok(model));
                }
            }
            else
            {
                comment = await _repo.Item()
                          .Where(c => c.Id == id)
                          .Include(c => c.MyChecks)
                          .Include(c => c.Project)
                          .ThenInclude(p => p.Category)
                          .Include(c => c.User)
                          .Include(c => c.SubComments)
                          .FirstOrDefaultAsync();

                if (comment != null)
                {
                    CommentAsIsDTO dto = comment.ConvertToAsIs(_mapper);
                    return(Ok(dto));
                }
            }
            return(NotFound(new ErrorDTO {
                Message = "user not found"
            }));
        }