public ActionResult Create(NoticeViewModel model) { ServiceResult result = new ServiceResult(); TempData["Service_Result"] = result; if (ModelState.IsValid) { try { NoticeService.Create(model); result.Message = "添加部门公告成功!"; LogHelper.WriteLog("添加部门公告成功"); return RedirectToAction("index"); } catch (Exception ex) { result.Message = Utilities.GetInnerMostException(ex); result.AddServiceError(result.Message); LogHelper.WriteLog("添加部门公告错误", ex); } } else { result.Message = "请检查表单是否填写完整!"; result.AddServiceError("请检查表单是否填写完整!"); } var list = DepartmentService.GetALL().Where(x => x.PID.Equals(null)); var hasPermission = CookieHelper.CheckPermission("boss"); if (!hasPermission) { var member = MemberService.Find(CookieHelper.MemberID); list = list.Where(x => x.ID == member.DepartmentID); } ViewBag.Data_DepartmentID = Utilities.GetSelectListData( list , x => x.ID, x => x.Name, true); return View(model); }
public ActionResult Edit(int ID) { var list = DepartmentService.GetALL().Where(x => x.PID.Equals(null)); var hasPermission = CookieHelper.CheckPermission("boss"); if (!hasPermission) { var member = MemberService.Find(CookieHelper.MemberID); list = list.Where(x => x.ID == member.DepartmentID); } var entity = NoticeService.Find(ID); var model = new NoticeViewModel() { ID = entity.ID, Content = entity.Content, DepartmentID = entity.DepartmentID, Name = entity.Name }; ViewBag.Data_DepartmentID = Utilities.GetSelectListData( list , x => x.ID, x => x.Name, model.DepartmentID, true); return View(model); }