public IActionResult Index() { ViewBag.CategorySelectList = new SelectList(_context.GetAllCategory().Select(o => o.CategoryKind), "CategoryKind"); var products = _context.GetAll(); var resultList = products .Select(result => new ProductIndexListingModel { Id = result.Id, ItemName = result.ItemName, Description = result.Description, Price = result.Price.ToString(), UploadTime = result.UploadTime.ToString(), Category = result.Category.CategoryKind, PersonName = result.Person.PersonName, PersonEmail = result.Person.Email }); var model = new ProductIndexModel() { Products = resultList }; return(View(model)); }
private IEnumerable <ProductDTO> Get() { var products = _context.GetAll(); var resultList = products .Select(result => new ProductDTO { Id = result.Id, ItemName = result.ItemName, Description = result.Description, Price = result.Price.ToString(), UploadTime = result.UploadTime.ToString(), Category = result.Category.CategoryKind, PersonName = result.Person.PersonName, PersonEmail = result.Person.Email }); return(resultList); }