public bool DeleteAccountPemission(string permissionId) { var _retVal = false; try { using (var db = new SKMContext()) { var AccountPemission = db.AccountPemissions.Where(p => p.PermissionId == permissionId).Include(c => c.Roles) .FirstOrDefault(); if (AccountPemission != null) { AccountPemission.Roles.Clear(); db.Entry(AccountPemission).State = EntityState.Deleted; } db.SaveChanges(); _retVal = true; } } catch (Exception) { } return(_retVal); }
public bool AddUpdatePermission(AccountPemission newPermission) { var retVal = false; try { using (var db = new SKMContext()) { var permission = db.AccountPemissions.FirstOrDefault(c => c.Name == newPermission.Name); if (permission == null) { db.AccountPemissions.Add(newPermission); db.Entry(newPermission).State = EntityState.Added; db.SaveChanges(); retVal = true; } else { retVal = true; } } } catch (Exception) { } return(retVal); }
public bool RemovePermission4Role(string roleId, string permissionId) { var _retVal = false; try { using (var db = new SKMContext()) { var role = db.Roles.Where(p => p.Id == roleId).Include(c => c.Permissions).FirstOrDefault(); var permission = db.AccountPemissions.Where(p => p.PermissionId == permissionId).Include(c => c.Roles) .FirstOrDefault(); if (role != null && role.Permissions.Contains(permission)) { role.Permissions.Remove(permission); //_role2Modify.LastModified = DateTime.Now; db.Entry(role).State = EntityState.Modified; db.SaveChanges(); _retVal = true; } } } catch (Exception) { } return(_retVal); }
public bool AddAllPermissions2Role(string roleId) { var _retVal = false; try { using (var db = new SKMContext()) { var role = db.Roles.Where(p => p.Id == roleId).Include(c => c.Permissions).FirstOrDefault(); if (role != null) { var permissions = db.AccountPemissions.Include(c => c.Roles).ToList(); foreach (var permission in permissions) { if (!role.Permissions.Contains(permission)) { role.Permissions.Add(permission); } } //role.LastModified = DateTime.Now; db.Entry(role).State = EntityState.Modified; db.SaveChanges(); _retVal = true; } } } catch { } return(_retVal); }
public bool AddPermissionToRole(string roleId, PermissionType permissionType) { var retVal = false; try { using (var db = new SKMContext()) { var role = db.Roles.Where(p => p.Id == roleId).Include(c => c.Permissions).FirstOrDefault(); if (role != null) { var permission = db.AccountPemissions.Where(p => p.Type == permissionType).Include(c => c.Roles).FirstOrDefault(); if (!role.Permissions.Contains(permission)) { role.Permissions.Add(permission); //role.LastModified = DateTime.Now; db.Entry(role).State = EntityState.Modified; db.SaveChanges(); } } } } catch (Exception ex) { throw ex; } return(retVal); }
public bool UpdateAccountPemission(AccountPemission permission) { var retVal = false; try { using (var db = new SKMContext()) { db.Entry(permission).State = EntityState.Modified; db.SaveChanges(); retVal = true; } } catch (Exception) { } return(retVal); }
public bool AddPermission(AccountPemission newPermission) { var retVal = false; try { using (var db = new SKMContext()) { db.AccountPemissions.Add(newPermission); db.Entry(newPermission).State = EntityState.Added; db.SaveChanges(); retVal = true; } } catch (Exception) { } return(retVal); }