Beispiel #1
0
        public ActionResult <Category> GetCategoryById(int id)
        {
            var categoryItem = _repository.GetCategoryById(id);

            if (categoryItem != null)
            {
                return(Ok(_mapper.Map <CategoryReadDto>(categoryItem)));
            }
            return(NotFound());
        }
Beispiel #2
0
        public ActionResult <CategoryReadDTO> GetCategoryById(int id)
        {
            var category = _repo.GetCategoryById(id);

            if (category != null)
            {
                return(Ok(_mapper.Map <CategoryReadDTO>(category)));
            }

            return(NotFound());
        }
Beispiel #3
0
        public ActionResult <Category> GetCategoryById(int Id)
        {
            var categoryItem = _repository.GetCategoryById(Id);


            if (categoryItem != null)
            {
                return(Ok(categoryItem));
            }
            return(NotFound());
        }
        // GET: Category/Details/5

        public IActionResult Details(int id)
        {
            var category = _categoryRepo.GetCategoryById(id);

            if (category == null)
            {
                return(NotFound());
            }

            return(View(category));
        }
Beispiel #5
0
        public ViewResult PieList(int categoryId)
        {
            var pies = categoryId == 0 ? _pieRepo.GetAllPies : _pieRepo.GetAllPies.Where(x => x.CategoryId == categoryId);
            var vm   = new PieVM
            {
                Pies       = pies,
                CategoryId = categoryId,
                Category   = _categoryRepo.GetCategoryById(categoryId)
            };

            return(View(vm));
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Category category = _repo.GetCategoryById((int)id);

            if (category == null)
            {
                return(HttpNotFound());
            }
            return(View(category));
        }
Beispiel #7
0
        public ActionResult <ProductReadDto> CreateProduct(ProductCreateDto productCreateDto)
        {
            if (_categoryRepo.GetCategoryById((int)productCreateDto.ProductCategoryId) == null)
            {
                return(NoContent());
            }
            var productModel = _mapper.Map <Product>(productCreateDto);

            _repository.CreateProduct(productModel);
            _repository.SaveChanges();

            var productReadDto = _mapper.Map <ProductReadDto>(productModel);

            return(CreatedAtRoute(nameof(GetProductById), new { Id = productReadDto }, productReadDto));
        }
Beispiel #8
0
        public PostRepo(IUrlHelper urlHelper, ICategoryRepo categoryRepo)
        {
            _urlHelper    = urlHelper;
            _categoryRepo = categoryRepo;

            _posts = new List <Post>()
            {
                new Post()
                {
                    Id       = 1,
                    Tags     = new string[] { "C#", "ASP.NET" },
                    Category = _categoryRepo.GetCategoryById(1),
                    FilePath = "/posts/publish-asp-on-linux.md",
                    Title    = "Publish an ASP.Net App on a Linux VPS",
                    Slug     = _urlHelper.CreateSlug("publish-a-asp-dotnet-app-on-linux"),
                    ImgPath  = "/posts/m.publish-asp-on-linux.assets/linux-penguin.jpg",
                    ImgAlt   = "linux penguin ",
                    Language = Post.Languages.EN,
                    Date     = new DateTime(2021, 02, 05)
                },

                //new Post() { Id = 2,
                //    Tags= new string[] {"C#", "ASP.NET" },
                //    Category=_categoryRepo.GetCategoryById(1),
                //    FileName = "~/posts/hard-to-say.md",
                //    Title="My super second Post",
                //    Slug = _urlHelper.CreateSlug( "hard to say"),
                //    ImgPath = "/posts/m.hard-to-say.assets/all-you-need-is-coffee.jpg",
                //    ImgAlt= "alt of an image",
                //    Language = Post.Languages.EN
                //},



                // new Post() {
                //     Id = 2,
                //     Tags= new string[] {"C#", "ASP.NET" },
                //     Category=_categoryRepo.GetCategoryById(1),
                //     FileName = "~/posts/hard-to-say.md",
                //     Title="My super second Post",
                //     Slug = _urlHelper.CreateSlug( "hard to say"),
                //     ImgPath = "/posts/m.hard-to-say.assets/all-you-need-is-coffee.jpg",
                //     ImgAlt= "alt of an image",
                //     Language = Post.Languages.EN
                // },

                //  new Post() { Id = 2, Tags= new string[] {"C#", "ASP.NET" }, Category=_categoryRepo.GetCategoryById(1),
                //    FileName = "~/posts/hard-to-say.md", Title="My super second Post", Slug = _urlHelper.CreateSlug( "hard to say"),
                //ImgPath = "/posts/m.hard-to-say.assets/all-you-need-is-coffee.jpg", ImgAlt= "alt of an image"},
            };
        }
Beispiel #9
0
        public Category GetCategoryById(int id)
        {
            Category category = repo.GetCategoryById(id);

            return(category);
        }