예제 #1
0
        public ActionResult CategoryDetail(int id)
        {
            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];
            GenericRepository <Category> catRepository   = unitOfWork.GetRepoInstance <Category>();
            GenericRepository <Employee> adminRepository = unitOfWork.GetRepoInstance <Employee>();
            Category cd = catRepository.GetBy(c => c.CategoryID == id).FirstOrDefault();
            Employee e  = adminRepository.GetBy(c => c.CategoryID == id && c.RoleID == 2).FirstOrDefault();

            if (e != null)
            {
                CatgeroyView catDetail = new CatgeroyView()
                {
                    CategoryID          = cd.CategoryID,
                    CategoryAdmin       = e.UserName,
                    CategoryDescription = cd.CategoryDescription,
                    CategoryName        = cd.CategoryName
                };
                return(View("CategoryDetail", catDetail));
            }
            else
            {
                CatgeroyView catDetail = new CatgeroyView()
                {
                    CategoryID          = cd.CategoryID,
                    CategoryAdmin       = "No Admin",
                    CategoryDescription = cd.CategoryDescription,
                    CategoryName        = cd.CategoryName
                };
                return(View("CategoryDetail", catDetail));
            }
        }
예제 #2
0
        public ActionResult EditCategory(CatgeroyView cat)
        {
            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];
            GenericRepository <Category> catRepository = unitOfWork.GetRepoInstance <Category>();
            Category cd = catRepository.GetBy(c => c.CategoryID == cat.CategoryID).FirstOrDefault();

            cd.CategoryName        = cat.CategoryName;
            cd.CategoryDescription = cat.CategoryDescription;
            catRepository.Edit(cd);
            unitOfWork.SaveChanges();
            return(RedirectToAction("CategoryDetail", new RouteValueDictionary(
                                        new { controller = "Admin", action = "CategoryDetail", id = cat.CategoryID })));
        }