Beispiel #1
0
        public async Task <ActionResult <CategoryDto> > GetCategoryById([FromRoute] int id)
        {
            var category = await repository.GetById(x => x.Id == id);

            if (category == null)
            {
                return(NotFound());
            }
            var categoryDto = mapper.Map <CategoryDto>(category);

            return(categoryDto);
        }
        public IActionResult Edit(int?id)
        {
            if (id == null || id == 0)
            {
                return(NotFound());
            }

            Category category = categoryDAO.GetById(id);

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

            return(View(category));
        }
Beispiel #3
0
        public IActionResult Edit(int id)
        {
            var category = _categoryRepos.GetById(id);

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

            return(View(new CategoryEditVM
            {
                Name = category.Name,
                Image = category.Image,
                UrlSlug = category.UrlSlug
            }));
        }
Beispiel #4
0
 public ActionResult ChangeName(EditCategoryViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(RedirectToAction("ManageCategories", "Admin"));
         //return Redirect(Request.UrlReferrer.ToString());
     }
     try
     {
         var category = _categoryRepo.GetById(model.EditedCategory.Id);
         category.Name = model.EditedCategory.Name;
         _categoryRepo.SaveChanges();
         return(RedirectToAction("ManageCategories", "Admin"));
     } catch (Exception e)
     {
         return(RedirectToAction("ManageCategories", "Admin"));
     }
 }
Beispiel #5
0
        public async Task <ActionResult <Category> > GetCategory(string id)
        {
            try
            {
                var result = await repo.GetById(id);

                if (result == null)
                {
                    return(NotFound($"Category with Id = {id} not found"));
                }

                return(result);
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  $"Error retrieving data from the database. Error message:{e.Message}"));
            }
        }
Beispiel #6
0
        public async Task <CategoryDTO> GetCategoryAsync(int id)
        {
            var category = await _categoryRepo.GetById(id);

            return(_mapper.Map <Category, CategoryDTO> (category));
        }
Beispiel #7
0
 public Task <Category> getById(long?id)
 {
     return(_repository.GetById(id));
 }