コード例 #1
0
        public void LinkAccountRole(Guid accountCode, Guid roleCode, bool isRKAdmin, Guid clientId)
        {
            using (var transaction = Connection.BeginTransaction())
            {
                try
                {
                    var _accountRole = ValidateField(accountCode, roleCode, isRKAdmin, clientId);

                    if (!_accountRole.IsNull())
                    {
                        _accountRole.Status     = true;
                        _accountRole.UpdateDate = DateTime.Now;
                    }
                    else
                    {
                        _accountRole = new AccountRole()
                        {
                            Code        = Guid.NewGuid(),
                            AccountCode = accountCode,
                            RoleCode    = roleCode,
                            Status      = true,
                        };
                    }

                    accountRoleRepository.Save(_accountRole);
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
コード例 #2
0
        public Role Save(Role role)
        {
            var roleOld = roleRepository.Get(role.Code, role.StoreCode);

            if (!roleOld.IsNull() && !role.Permissions.IsNull())
            {
                permissionRepository.Delete(roleOld.Permissions);
            }

            if (!roleOld.IsNull() && !role.AccountRoles.IsNull())
            {
                accountRoleRepository.Delete(roleOld.AccountRoles);
            }

            if (!roleOld.IsNull() && !role.Restrictions.IsNull())
            {
                restrictionRepository.Delete(roleOld.Restrictions);
            }

            if (!role.Permissions.IsNull())
            {
                role.Permissions.ForEach(p =>
                {
                    p.RoleCode   = role.Code;
                    p.SaveDate   = DateTime.Now;
                    p.UpdateDate = DateTime.Now;

                    permissionRepository.Save(p);
                });
            }

            if (!role.AccountRoles.IsNull())
            {
                role.AccountRoles.ForEach(a =>
                {
                    a.RoleCode   = role.Code;
                    a.SaveDate   = DateTime.Now;
                    a.UpdateDate = DateTime.Now;

                    accountRoleRepository.Save(a);
                });
            }

            if (!role.Restrictions.IsNull())
            {
                role.Restrictions.ForEach(a =>
                {
                    a.RoleCode   = role.Code;
                    a.SaveDate   = DateTime.Now;
                    a.UpdateDate = DateTime.Now;

                    restrictionRepository.Save(a);
                });
            }

            return(roleRepository.Save(role));
        }