Exemple #1
0
 public ActionResult Create(GroupViewModel model)
 {
     var Roles = GetForeignData();
     ViewBag.Data_Roles = Roles;
     ServiceResult result = new ServiceResult();
     TempData["Service_Result"] = result;
     if (ModelState.IsValid)
     {
         try
         {
             Group entity = new Group();
             entity.Name = model.Name;
             entity.Description = model.Description;
             var RolesArray = model.Roles.Split(',').Select(x => Convert.ToInt32(x)).ToList();
             var RoleList = RolesService.GetALL().Where(x => RolesArray.Contains(x.ID));
             entity.Roles.AddRange(RoleList);
             GroupService.Create(entity);
             result.Message = "添加群组成功!";
             LogHelper.WriteLog("添加群组成功");
             return RedirectToAction("index");
         }
         catch (DbEntityValidationException ex)
         {
             result.Message = Utilities.GetInnerMostException(ex);
             result.AddServiceError(result.Message);
             LogHelper.WriteLog("添加群组错误", ex);
             return View(model);
         }
     }
     else
     {
         result.Message = "请检查表单是否填写完整!";
         result.AddServiceError("请检查表单是否填写完整!");
         return View(model);
     }
 }
Exemple #2
0
 public ActionResult Edit(int ID)
 {
     GroupViewModel model = new GroupViewModel();
     var entity = GroupService.GetALL().Include(x => x.Roles).Single(x => x.ID == ID);
     model.Name = entity.Name;
     model.ID = entity.ID;
     model.Description = entity.Description;
     List<int> RolesList = new List<int>();
     RolesList = entity.Roles.Select(x => x.ID).ToList();
     var Roles = GetForeignData(RolesList);
     ViewBag.Data_Roles = Roles;
     return View(model);
 }