Example #1
0
        // GET: Products/Create
        public ActionResult Create()
        {
            var categories = categoryRepo.GetAll();

            ViewBag.CategoryList = new SelectList(categories, "Id", "CategoryName");
            return(View());
        }
Example #2
0
        //[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));
            }
        }
Example #3
0
        public async Task <IActionResult> AddProduct()
        {
            AddProductViewModel model = new AddProductViewModel();

            model.Categories = await categoryRepo.GetAll();

            return(View(model));
        }
Example #4
0
        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());
        }
Example #5
0
        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));
        }
Example #6
0
        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));
        }
Example #9
0
        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));
        }
Example #10
0
        public ActionResult <string> GetAll()
        {
            var category = _repository.GetAll();

            if (category != null)
            {
                return(Ok(JsonConvert.SerializeObject(category, Formatting.Indented)));
            }
            return(NotFound());
        }
Example #11
0
        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));
        }
Example #12
0
        public async Task <IActionResult> Index()
        {
            var list = _categoryRepos.GetAll().ToList();

            //await _categoryRepos.Add(
            //    new Category()
            //    {
            //        Id
            //    });
            return(View(list));
        }
Example #13
0
 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}"));
     }
 }
Example #14
0
        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));
            }
        }
Example #15
0
        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());
        }
Example #17
0
        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
            }));
        }
Example #18
0
        public ActionResult <IList <Category> > Get()
        {
            IEnumerable <Category> categories = _repo.GetAll().ToList();

            return(Ok(categories));
        }
Example #19
0
 public IActionResult Index()
 {
     return(View(_repo.GetAll()));
 }
Example #20
0
        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());
 }
Example #22
0
 public IActionResult Get()
 {
     return(Ok(_categoryRepo.GetAll()));
 }
Example #23
0
 /*Chỉ có 1 action duy nhất là Invoke()*/
 public IViewComponentResult Invoke()
 {
     return(View("Default", _categoryRepo.GetAll()));
 }
Example #24
0
 public IEnumerable <CategoryViewModel> GetAll()
 {
     return(_categoryRepo.GetAll());
 }
Example #25
0
        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()));
 }