public ActionResult Create(TcNoticeViewModel model) { ServiceResult result = new ServiceResult(); var DepartmentArray = new List<int>(); TempData["Service_Result"] = result; if (ModelState.IsValid) { try { DepartmentArray = model.DepartmentID.Split(',').Select(x => Convert.ToInt32(x)).ToList(); TcNoticeService.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("请检查表单是否填写完整!"); } ViewBag.Data_DepartmentID = Utilities.GetSelectListData( DepartmentService.GetALL() .Where(x => x.PID.Equals(null)), x => x.ID, x => x.Name, DepartmentArray, false); return View(model); }
public ActionResult Edit(int ID) { var entity = TcNoticeService.GetALL().Include(x => x.Department).Single(x => x.ID == ID); var model = new TcNoticeViewModel() { ID = entity.ID, Content = entity.Content, AttachmentPath = entity.AttachmentPath, Name = entity.Name, DepartmentID = String.Join(",", entity.Department.Select(x => x.ID)), }; var DepartmentArray = new List<int>(); if (!string.IsNullOrEmpty(model.DepartmentID)) { DepartmentArray = model.DepartmentID.Split(',').Select(x => Convert.ToInt32(x)).ToList(); } ViewBag.Data_DepartmentID = Utilities.GetSelectListData( DepartmentService.GetALL() .Where(x => x.PID.Equals(null)), x => x.ID, x => x.Name, DepartmentArray, false); return View(model); }