Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
            }
        }