RoleController.cs
1 public class RoleController : Controller 2 { 3 // 4 // GET: /Admin/Role/ 5 6 RoleRepository roleRepository = new RoleRepository(); 7 8 // BMK 角色列表 9 [Authorize] 10 public ActionResult Index( int? page) 11 { 12 var source = roleRepository.GetPageModelList( 15, page ?? 1, - 1); 13 return View(source); 14 } 15 // BMK 角色查询 16 [Authorize] 17 public ActionResult Search( int? page) 18 { 19 return View(); 20 } 21 // BMK 角色添加页面 22 [Authorize] 23 public ActionResult Add() 24 { 25 return View(); 26 } 27 // BMK 角色添加提交数据 28 [Authorize, HttpPost, ValidateInput( false)] 29 public ActionResult Add(Role model, FormCollection fc) 30 { 31 model.State = 1; 32 model.CreateTime = DateTime.Now; 33 roleRepository.SaveOrEditModel(model); 34 return RedirectToAction( " Index "); 35 } 36 // BMK 角色修改页面 37 [Authorize] 38 public ActionResult Edit( int id) 39 { 40 var model = roleRepository.GetModel(id); 41 if (model != null) 42 { 43 ViewData[ " State "] = SelectListHelper.GetStateSelectList(model.State); 44 return View(model); 45 } 46 else 47 return View( " 404 "); 48 } 49 // BMK 角色修改提交数据 50 [Authorize, HttpPost, ValidateInput( false)] 51 public ActionResult Edit( int id, FormCollection fc) 52 { 53 var model = roleRepository.GetModel(id); 54 if (model != null) 55 { 56 UpdateModel(model); 57 roleRepository.SaveOrEditModel(model); 58 return RedirectToAction( " index "); 59 } 60 else 61 return View( " 404 "); 62 } 63 // BMK 角色删除 64 [Authorize] 65 public ActionResult Delete( int id) 66 { 67 var model = roleRepository.GetModel(id); 68 if (model != null) 69 { 70 roleRepository.DeleteModel(id); 71 return RedirectToAction( " Index "); 72 } 73 else 74 return View( " 404 "); 75 }
UserController.cs
1 public class UserController : Controller 2 { 3 UserRepository userrepository = new UserRepository(); 4 RoleRepository rolerepository = new RoleRepository(); 5 UserRoleMappingRoleMappingRepository urmrepository = new UserRoleMappingRoleMappingRepository(); 6 7 // BMK 用户列表 8 [Authorize] 9 public ActionResult Index( int? page) 10 { 11 var source = userrepository.GetPageModelList( 15, page ?? 1, - 1); 12 return View(source); 13 } 14 // BMK 用户查询 15 [Authorize] 16 public ActionResult Search( int? page) 17 { 18 string logname = ""; 19 string mobile = ""; 20 string email = ""; 21 if (page == null) 22 { 23 logname = Request.Form[ " LogName "]; 24 CookieHelper.SetObj( " LogName ", 0, logname); 25 mobile = Request.Form[ " Mobile "]; 26 CookieHelper.SetObj( " Mobile ", 0, mobile); 27 email = Request.Form[ " Email "]; 28 CookieHelper.SetObj( " Email ", 0, email); 29 } 30 else 31 { 32 logname = CookieHelper.GetValue( " LogName "); 33 mobile = CookieHelper.GetValue( " Mobile "); 34 email = CookieHelper.GetValue( " Email "); 35 36 } 37 var query = QueryBuilder.Create<User>() 38 .Like(d => d.LogName, logname); 39 var modellist = userrepository.GetModelList().Where(query.Expression); 40 var source = userrepository.GetPageModelList(modellist, 15, page ?? 1); 41 return View(source); 42 } 43 // BMK 用户添加页面 44 [Authorize] 45 public ActionResult Add(User model) 46 { 47 var rolelist = rolerepository.GetModelListByState( 1); 48 ViewData[ " roletype "] = SelectListExtension.ToSelectList(rolelist, 49 d => d.RoleName, 50 d => d.RoleID.ToString()); 51 return View(); 52 } 53 // BMK 用户添加提交数据 54 [Authorize, AcceptVerbs(HttpVerbs.Post)] 55 public ActionResult Add(User model, UserRoleMapping URM, int roletype, FormCollection fc) 56 { 57 model.State = 1; 58 model.CreateTime = DateTime.Now; 59 model.PassWord = StringHelper.GetMD5(Request.Form[ " PassWord "]); 60 userrepository.SaveOrEditModel(model); 61 // 添加用户角色类型 62 URM.UserID = model.UserID; 63 URM.RoleID = roletype; 64 urmrepository.SaveOrEditModel(URM); 65 return RedirectToAction( " Index "); 66 } 67 // BMK 用户修改页面 68 [Authorize] 69 public ActionResult Edit( int id) 70 { 71 var model = userrepository.GetModel(id); 72 if (model != null) 73 { 74 var rolelist = rolerepository.GetModelListByState( 1); 75 ViewData[ " roletype "] = SelectListExtension.ToSelectList(rolelist, 76 d => d.RoleName, 77 d => d.RoleID.ToString()); 78 ViewData[ " State "] = SelectListHelper.GetStateSelectList(model.State); 79 return View(model); 80 } 81 else 82 return View( " 404 "); 83 } 84 // BMK 用户修改提交数据 85 [Authorize, AcceptVerbs(HttpVerbs.Post)] 86 public ActionResult Edit( int id, FormCollection fc) 87 { 88 var model = userrepository.GetModel(id); 89 90 if (model != null) 91 { 92 string password = model.PassWord; 93 if (Request.Form[ " PassWord "] != "") 94 { 95 UpdateModel(model); 96 model.PassWord = StringHelper.GetMD5(Request.Form[ " PassWord "]); 97 userrepository.SaveOrEditModel(model); 98 } 99 else 100 { 101 UpdateModel(model); 102 model.PassWord = password; 103 userrepository.SaveOrEditModel(model); 104 } 105 return RedirectToAction( " index "); 106 } 107 else 108 return View( " 404 "); 109 } 110 public IQueryable<UserRoleMapping> urmlist { get; set; } 111 // BMK 用户删除 112 [Authorize] 113 public ActionResult Delete( int id) 114 { 115 var model = userrepository.GetModel(id); 116 117 if (model != null) 118 { 119 urmlist = urmrepository.GetModelListByUserID(id); 120 if (urmlist.Count() > 0) 121 { 122 foreach ( var item in urmlist) 123 { 124 urmrepository.DeleteModel(item.UserRoleMappingID); 125 } 126 userrepository.DeleteModel(id); 127 } 128 return RedirectToAction( " Index "); 129 } 130 else 131 return View( " 404 "); 132 }