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); }
public HttpStatusCode CreateCatalog(CreateCatalogDto catalogDto, string userId) { Catalog catalog = CatalogsFactory.CatalogToDbo(catalogDto); ApplicationUser user = _ctx.Users.FirstOrDefault(f => f.Id == userId); catalog.User = user; catalog.UserId = user.Id; try { _ctx.Catalogs.Add(catalog); _ctx.SaveChanges(); return(HttpStatusCode.OK); } catch (Exception ex) { return(HttpStatusCode.InternalServerError); } }