Exemplo n.º 1
0
 public void Update(Roles model)
 {
     var target = GetALL().Include(x => x.Permissions).Single(x => x.ID == model.ID);
     db.Attach<Roles>(target);
     target.Description = model.Description;
     target.Name = model.Name;
     var PermissionList = model.Permissions;
     var currentPermissionArray = target.Permissions.Select(x => x.ID).ToList();
     foreach (Permissions ps in PermissionsService.GetALL())
     {
         if (PermissionList.Count(x => x.ID == ps.ID) > 0)
         {
             if (!currentPermissionArray.Contains(ps.ID))
             {
                 target.Permissions.Add(ps);
             }
         }
         else
         {
             if (currentPermissionArray.Contains(ps.ID))
             {
                 target.Permissions.Remove(ps);
             }
         }
     }
     db.Commit();
 }
Exemplo n.º 2
0
 public ActionResult Create(RolesViewModel model)
 {
     var permissions = GetGroupForeignData();
     ViewBag.Data_Permissions = permissions;
     ServiceResult result = new ServiceResult();
     TempData["Service_Result"] = result;
     if (ModelState.IsValid)
     {
         try
         {
             Roles entity = new Roles();
             entity.Name = model.Name;
             entity.Description = model.Description;
             var permissionsArray = model.Permissions.Split(',').Select(x => Convert.ToInt32(x)).ToList();
             var PermissionList = PermissionsService.GetALL().Where(x => permissionsArray.Contains(x.ID));
             entity.Permissions.AddRange(PermissionList);
             RolesService.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);
     }
 }
Exemplo n.º 3
0
 public void Delete(Roles model)
 {
     var target = Find(model.ID);
     db.Remove<Roles>(target);
     db.Commit();
 }
Exemplo n.º 4
0
 public void Create(Roles model)
 {
     db.Add<Roles>(model);
     db.Commit();
 }