public ActionResult Edit(int id) { Category cat = new Category(); cat = _repo.Get(id); CategoriesModel model = new CategoriesModel(); model.ID = cat.ID; model.CategoryName = cat.CategoryName; return(View(model)); }
//public IActionResult Data_Table([DataSourceRequest] DataSourceRequest request) //{ // return Json(_repository.GetSubCategoriesWithCategory().ToDataSourceResult(request)); //} // GET: Admin/Categories/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var category = await _repository.Get(id.Value); if (category == null) { return(NotFound()); } return(View(category)); }
public void ThrowsExceptionWhenRecordFoundDoesNotBelongToTheUser() { // Arrange. this.categoryId = 1; this.userId = 2; // Act. Exception caughtException = null; try { using (CheckbookContext context = new CheckbookContext(this.dbContextOptions)) { CategoriesRepository repository = new CategoriesRepository(context); repository.Get(this.categoryId, this.userId); } } catch (Exception ex) { caughtException = ex; } // Assert. Assert.IsNotNull(caughtException, "An exception should be thrown."); Assert.IsInstanceOfType(caughtException, typeof(NotFoundException), "This should be an argument exception."); string exceptionMessage = "The category was not found."; Assert.AreEqual(exceptionMessage, caughtException.Message, "The exception message should be correct."); }
public async Task <ActionResult <CategoriesViewModel> > Get(int id) { var category = await _repository.Get(id); if (category == null) { return(NotFound()); } CategoriesViewModel maped = _mapper.Map <CategoriesViewModel>(category); return(Ok(maped)); }
public async Task <ActionResult <IList <Categories> > > Get() { var categories = await _categoriesRepository.Get(); if (categories == null) { return(NotFound()); } Response.Headers.Add("X-Total-Count", new StringValues(categories.Count.ToString())); Response.Headers.Add("page-size", new StringValues(categories.Count.ToString())); return(Ok(categories)); }
public void ReturnsCategoryFromContext() { // Arrange. this.categoryId = 1; this.userId = 1; // Act. Category actual; using (CheckbookContext context = new CheckbookContext(this.dbContextOptions)) { CategoriesRepository repository = new CategoriesRepository(context); actual = repository.Get(this.categoryId, this.userId); } // Assert. Category expected = this.entities.ElementAt(0); Assert.AreEqual(expected.Id, actual.Id, "The ID for the entity should match."); Assert.AreEqual(expected.Name, actual.Name, "The name for the entity should match."); Assert.AreEqual(expected.UserId, actual.UserId, "The user ID for the entity should match."); }
public Category GetCategory(int categoryId) { return(categoriesRepository.Get(categoryId)); }
public IEnumerable <Category> Get(string userId) { return(_repo.Get(userId)); }