public SupplyResponse Get(int id) { var category = _dbContext.Category.Include(a => a.CategoryItems).ThenInclude(a => a.VirtualItem).SingleOrDefault(p => p.CategoryId == id); if (category == null) { return(SupplyResponse.NotFound("category", id + "")); } var categoryItemResponse = new CategoryItemResponse { Category = category, VirtualItemId = new List <string>() }; if (category.CategoryItems != null) { foreach (var categoryItem in category.CategoryItems) { categoryItemResponse.VirtualItemId.Add(categoryItem.VirtualItem.VirtualItemId); } category.CategoryItems = null; } return(SupplyResponse.Ok(categoryItemResponse)); }
public SupplyResponse Get() { var categories = _dbContext.Category.Include(a => a.CategoryItems).ThenInclude(a => a.VirtualItem).Select(p => p); var categoryItemResponses = new List <CategoryItemResponse>(); foreach (var category in categories) { var categoryItemResponse = new CategoryItemResponse { Category = category, VirtualItemId = new List <string>() }; if (category.CategoryItems != null) { foreach (var categoryItem in category.CategoryItems) { categoryItemResponse.VirtualItemId.Add(categoryItem.VirtualItem.VirtualItemId); } category.CategoryItems = null; } categoryItemResponses.Add(categoryItemResponse); } return(SupplyResponse.Ok(categoryItemResponses)); }
public CategoryItemResponse Item([FromBody] CategoryItemRequest request) { CategoryItemResponse response = new CategoryItemResponse(); if (request.Id <= 0) { response.Status = -1; return(response); } CategoryEntity entity = categoryRepository.GetById(request.Id); if (entity == null) { response.Status = 404; return(response); } response.Item = categoryConvertor.toLessVo(entity); response.Status = 1; return(response); }