// GET: Products/Create public ActionResult Create() { var categories = categoryRepo.GetAll(); ViewBag.CategoryList = new SelectList(categories, "Id", "CategoryName"); return(View()); }
//[Route("post/edit/{id}")] public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { var post = await _postRepo.GetPostAsync(id); if (post == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (!(post.User.Id == User.Identity.GetUserId() || User.IsInRole("Admin"))) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var mapedPost = _mapper.Map <Post, UserPostEditViewModel>(post); var categories = _categoryRepo.GetAll(); mapedPost.SelectedCategory = post.CategoryId; mapedPost.Categories = categories; return(View(mapedPost)); } catch (Exception e) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
public async Task <IActionResult> AddProduct() { AddProductViewModel model = new AddProductViewModel(); model.Categories = await categoryRepo.GetAll(); return(View(model)); }
public void ShouldDeleteACategoryEntityFromDbSet() { _repo.AddRange(new List <Category> { new Category { CategoryName = "Foo" }, }); Assert.Equal(1, _repo.Table.Count()); var category = _repo.GetAll().First(); var count = _repo.Delete(category); Assert.Equal(1, count); Assert.Equal(0, _repo.Table.Count()); }
public async Task <IActionResult> Index(CategoryFilterVM filter, int page = 1) { CategoryVM model = new CategoryVM(); int pageSize = 2; var query = _categoryRepos.GetAll(); if (!string.IsNullOrEmpty(filter.Name)) { query = query.Where(x => x.Name.Contains(filter.Name)); } if (filter.Id != 0) { query = query.Where(x => x.Id == filter.Id); } int pageNo = page - 1; model.list = query.OrderBy(x => x.Id) .Skip(pageNo * pageSize) .Take(pageSize) .ToList(); int allCount = query.Count(); model.Page = page; model.maxPage = (int)Math.Ceiling((double)allCount / pageSize); model.CategoryFilter = filter; return(View(model)); }
public async Task <ActionResult <List <CategoryDto> > > GetAllCategory([FromQuery] PaginationDto pagination) { var categories = await repository.GetAll(HttpContext, pagination); var categoriesDto = mapper.Map <List <CategoryDto> >(categories); return(categoriesDto); }
public IActionResult GetAll() { IEnumerable <Category> categories = _repo.GetAll(); IEnumerable <CategoryReadDTO> readCat = _mapper.Map <IEnumerable <CategoryReadDTO> >(categories); return(Ok(readCat)); }
public ViewViewComponentResult Invoke() { var model = new CategoryListViewModel { //Kategori listemizi partial kullanmak istediğimizi varsayalım. Categories = _categoryRepository.GetAll().ToList() }; return(View(model)); }
public async Task <IViewComponentResult> InvokeAsync() { var cats = _categoryRepo.GetAll(); if (cats == null) { return(new ContentViewComponentResult("There was an error getting the categories")); } return(View("MenuView", cats)); }
public ActionResult <string> GetAll() { var category = _repository.GetAll(); if (category != null) { return(Ok(JsonConvert.SerializeObject(category, Formatting.Indented))); } return(NotFound()); }
public PartialViewResult RightSearchWindow() { var categories = _categoryRepo.GetAll(); CategoriesWithLastPosts model = new CategoriesWithLastPosts(); model.Categories = categories; var recentPosts = _postRepo.GetRecentPosts(_settingsRepo.GetSettings().RecentPosts); model.RecentPosts = recentPosts; return(PartialView("_RightSearchWindow", model)); }
public async Task <IActionResult> Index() { var list = _categoryRepos.GetAll().ToList(); //await _categoryRepos.Add( // new Category() // { // Id // }); return(View(list)); }
public async Task <ActionResult> GetCategories() { try { return(Ok(await repo.GetAll())); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, $"Error retrieving data from the database. Error message:{e.Message}")); } }
public ActionResult ManageCategories() { CategoryViewModel model = new CategoryViewModel(); try { var categories = _categoryRepo.GetAll(); model.EditCategoryModel.Categories = categories; return(View(model)); } catch (Exception e) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
public ActionResult <IEnumerable <Category> > GetCategories() { try { var categories = _categoryRepo.GetAll().ToList(); if (categories == null) { return(Ok()); // Bij lege lijst geen error maar de lege lijst terug geven } return(Ok(categories)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public void ShouldAddSeveralCategories() { var categories = new List <Category>() { new Category { CategoryName = "Foo" }, new Category { CategoryName = "Bar" }, new Category { CategoryName = "FooBar" } }; var count = _repo.AddRange(categories); Assert.Equal(3, count); Assert.Equal(3, _repo.GetAll().Count()); Assert.Equal(3, _repo.Table.Count()); }
public ViewResult List(string category) { IEnumerable <Audio> _headphones; string currentCategory; if (string.IsNullOrEmpty(category)) { _headphones = _headphonesRepo.GetAll().OrderBy(p => p.HeadphonesId); currentCategory = "All headphones"; } else { _headphones = _headphonesRepo.GetAll().Where(p => p.Category.CategoryName == category).OrderBy(p => p.HeadphonesId); currentCategory = _categoryRepo.GetAll().FirstOrDefault(c => c.CategoryName == category)?.CategoryName; } return(View(new HeadphonesListViewModel { Headphones = _headphones, CurrentCategory = currentCategory })); }
public ActionResult <IList <Category> > Get() { IEnumerable <Category> categories = _repo.GetAll().ToList(); return(Ok(categories)); }
public IActionResult Index() { return(View(_repo.GetAll())); }
public IViewComponentResult Invoke() { var categories = _categoryRepo.GetAll().OrderBy(c => c.CategoryName); return(View(categories)); }
public List <CategoryDTO> GetAll() { return(categoryRepo.GetAll().Select(a => mapper.Map <CategoryDTO>(a)).ToList()); }
public IActionResult Get() { return(Ok(_categoryRepo.GetAll())); }
/*Chỉ có 1 action duy nhất là Invoke()*/ public IViewComponentResult Invoke() { return(View("Default", _categoryRepo.GetAll())); }
public IEnumerable <CategoryViewModel> GetAll() { return(_categoryRepo.GetAll()); }
public List <CategoryDTO> GetCategories() { var categories = _categoryRepo.GetAll().ToList(); return(_mapper.Map <List <Category>, List <CategoryDTO> > (categories)); }
// GET: Categories public ActionResult Index() { return(View(categoryRepo.GetAll())); }