public static CategoryBaseWithCheck ConvertToBaseWithCheck(this Category model, IMapper _mapper) { CategoryBaseWithCheck category = _mapper.Map <Category, CategoryBaseWithCheck>(model); category.Checks = model.Checks.Select(c => c.Convert <Check, BaseCheck>(_mapper)).ToList(); return(category); }
public async ValueTask <IActionResult> Get(int id, bool projects = false) { Category category = null; if (!projects) { category = await _repo.Item() .Where(c => c.Id == id) .Include(c => c.Checks) .FirstOrDefaultAsync(); if (category != null) { CategoryBaseWithCheck model = category.ConvertToBaseWithCheck(_mapper); return(Ok(model)); } } else { category = await _repo.Item() .Where(c => c.Id == id) .Include(c => c.Checks) .Include(c => c.Projects) .ThenInclude(p => p.Comments) .FirstOrDefaultAsync(); if (category != null) { CategoryDTO model = category.ConvertToDTO(_mapper); CategoryProjectDTO dto = new CategoryProjectDTO { Category = model, Total = category.Projects.Count() }; return(Ok(dto)); } } return(NotFound(new ErrorDTO { Message = "Item not found" })); }