Пример #1
0
        public ActionResult EditCategory(string categoryId)
        {
            System.Diagnostics.Debug.WriteLine("Got value: " + categoryId);

            int nCategoryId;

            try
            {
                nCategoryId = Convert.ToInt32(categoryId);
            }
            catch (Exception e)
            {
                LogHandler.WriteToLog(e);
                ViewBag.Title = "Error";
                ViewBag.Message = "Invalid category id: " + categoryId;
                return View("~/Views/Shared/Result.cshtml");
            }

            var category = categoryBLL.GetCategory(nCategoryId);

            if (category == null)
            {
                ViewBag.Title = "Error";
                ViewBag.Message = "Couldnt find a category with id: " + categoryId;
                return View("~/Views/Shared/Result.cshtml");
            }

            var categoryView = new CategoryView()
            {
                CategoryId = category.CategoryId,
                CategoryName = category.Name
            };

            ViewBag.Category = categoryView;

            return View();
        }
Пример #2
0
        public ActionResult Index()
        {
            if ((Session["Admin"] == null ? false : (bool)Session["Admin"]))
            {
                var allCategories = categoryBLL.GetAllCategoryModels();
                var categoryViews = new List<CategoryView>();

                foreach (var category in allCategories)
                {
                    var categoryView = new CategoryView()
                    {
                        CategoryId = category.CategoryId,
                        CategoryName = category.CategoryName
                    };
                    categoryViews.Add(categoryView);
                }

                ViewBag.Categories = categoryViews;

                return View("ListCategory");
            }
            return RedirectToAction("Index", "Home");
        }
Пример #3
0
        public ActionResult DeleteCategory(string CategoryId)
        {
            int nCategoryId;

            try
            {
                nCategoryId = Convert.ToInt32(CategoryId);
            }
            catch (Exception e)
            {
                LogHandler.WriteToLog(e);
                ViewBag.Title = "Error";
                ViewBag.Message = "Invalid category id: " + CategoryId;
                return View("~/Views/Shared/Result.cshtml");
            }

            var category = categoryBLL.GetCategoryModel(nCategoryId);

            if (category == null)
            {
                ViewBag.Title = "Error";
                ViewBag.Message = "Couldnt find a category with the id: " + CategoryId;
                return View("~/Views/Shared/Result.cshtml");
            }

            var categoryView = new CategoryView()
            {
                CategoryId = category.CategoryId,
                CategoryName = category.CategoryName
            };

            ViewBag.Category = categoryView;

            return View();
        }