예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }