Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        //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));
        }
Ejemplo n.º 3
0
            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));
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
            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.");
            }
Ejemplo n.º 7
0
 public Category GetCategory(int categoryId)
 {
     return(categoriesRepository.Get(categoryId));
 }
Ejemplo n.º 8
0
 public IEnumerable <Category> Get(string userId)
 {
     return(_repo.Get(userId));
 }