Ejemplo n.º 1
0
 public void Update(Group model)
 {
     var target = GetALL().Include(x => x.Roles).Single(x => x.ID == model.ID);
     db.Attach<Group>(target);
     target.Description = model.Description;
     target.Name = model.Name;
     var RoleList = model.Roles;
     var currentPermissionArray = target.Roles.Select(x => x.ID).ToList();
     foreach (Roles ps in RolesService.GetALL())
     {
         if (RoleList.Count(x => x.ID == ps.ID) > 0)
         {
             if (!currentPermissionArray.Contains(ps.ID))
             {
                 target.Roles.Add(ps);
             }
         }
         else
         {
             if (currentPermissionArray.Contains(ps.ID))
             {
                 target.Roles.Remove(ps);
             }
         }
     }
     db.Commit();
 }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
0
 public void Delete(Group model)
 {
     var target = Find(model.ID);
     db.Remove<Group>(target);
     db.Commit();
 }
Ejemplo n.º 4
0
 public void Create(Group model)
 {
     db.Add<Group>(model);
     db.Commit();
 }