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)); }
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 })); }
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")); } }
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}")); } }
public async Task <CategoryDTO> GetCategoryAsync(int id) { var category = await _categoryRepo.GetById(id); return(_mapper.Map <Category, CategoryDTO> (category)); }
public Task <Category> getById(long?id) { return(_repository.GetById(id)); }