public CatalogViewModel GetCatalogById(int catalogId) { Catalog catalog = _ctx.Catalogs.FirstOrDefault(f => f.Id == catalogId); ApplicationUser user = _ctx.Users.FirstOrDefault(f => f.Id == catalog.UserId); CatalogViewModel catalogViewModel = CatalogsFactory.CatalogToViewModel(catalog, user.UserName); return(catalogViewModel); }
public List <CatalogViewModel> GetAllCatalogs() { List <Catalog> catalogs = _ctx.Catalogs.ToList(); List <CatalogViewModel> catalogViewModelsList = new List <CatalogViewModel>(); catalogs.ForEach(catalog => { ApplicationUser user = _ctx.Users.FirstOrDefault(f => f.Id == catalog.UserId); catalogViewModelsList.Add(CatalogsFactory.CatalogToViewModel(catalog, user.UserName)); }); return(catalogViewModelsList); }