Esempio n. 1
0
 public ActionResult Create(RoleModel model)
 {
     var permissions = GetGroupForeignData();
     ViewBag.Data_Permissions = permissions;
     if (ModelState.IsValid)
     {
         try
         {
             Roles rls = new Roles();
             rls.Name = model.Name;
             rls.Description = model.Description;
             var permissionsArray = model.Permissions.Split(',').Select(x => Convert.ToInt32(x)).ToList();
             var PermissionList = permissionService.GetALL(permissionsArray);
             rls.Permissions.AddRange(PermissionList);
             roleService.Create(rls);
             return RedirectToAction("index");
         }
         catch (Exception ex)
         {
             ViewBag.Message = ex.Message;
             return View(model);
         }
     }
     else
     {
         return View(model);
     }
 }
Esempio n. 2
0
 public ActionResult Edit(int id)
 {
     RoleModel rml = new RoleModel();
     Roles rs = new Roles();
     rs = roleService.IncludePermissionsFind(id);
     rml.ID = rs.ID;
     rml.Name = rs.Name;
     rml.Description = rs.Description;
     List<int> PermissionsList = new List<int>();
     PermissionsList = rs.Permissions.Select(x => x.ID).ToList();
     var permissions = GetGroupForeignData(PermissionsList);
     ViewBag.Data_Permissions = permissions;
     return View(rml);
 }
Esempio n. 3
0
 public ActionResult Edit(RoleModel model)
 {
     var permissionsArray = model.Permissions.Split(',').Select(x => Convert.ToInt32(x)).ToList();
     var permissions = GetGroupForeignData(permissionsArray);
     ViewBag.Data_Permissions = permissions;
     if (ModelState.IsValid)
     {
         try
         {
             roleService.Update(model);
             return RedirectToAction("index");
         }
         catch (Exception ex)
         {
             ViewBag.Message = ex.Message;
             return View(model);
         }
     }
     else
     {
         return View(model);
     }
 }
Esempio n. 4
0
 public void Update(RoleModel model)
 {
     var permissionsArray = model.Permissions.Split(',').Select(x => Convert.ToInt32(x)).ToList();
     var target = IncludePermissionsFind(model.ID);
     DB_Service.Attach<Roles>(target);
     target.Name = model.Name;
     target.Description = model.Description;
     var PermissionList = PermissionService.GetALL(permissionsArray);
     var currentPermissionArray = target.Permissions.Select(x => x.ID).ToList();
     foreach (Permissions ps in PermissionService.GetALL())
     {
         if (permissionsArray.Contains(ps.ID))
         {
             if (!currentPermissionArray.Contains(ps.ID))
             {
                 target.Permissions.Add(ps);
             }
         }
         else
         {
             if (currentPermissionArray.Contains(ps.ID))
             {
                 target.Permissions.Remove(ps);
             }
         }
     }
     DB_Service.Commit();
 }