Exemplo n.º 1
0
        public AddRoleModel()
        {
            mRole = new Role();

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cmsWebServiceClient.GetIssueCategoriesCompleted += cmsWebServiceClient_GetIssueCategoriesCompleted;
            cmsWebServiceClient.GetIssueCategoriesAsync();

            OkButtonCommand = new DelegateCommand<object>(OkButtonHander, CanExecuteOkButtonHandler);
            CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, CanExecuteOkButtonHandler);
        }
Exemplo n.º 2
0
        public RoleControl(int roleId)
        {
            InitializeComponent();

            mRoleId = roleId;

            mViewModel = new RoleControlViewModel(roleId);
            mViewModel.ViewModelLoaded += () =>
            {
                DataContext = mViewModel;
                mRole = mViewModel.Role;
                IsBusyIndicator.IsBusy = true;
                GetPrivileges();
            };
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Save role with Privileges
        /// </summary>
        /// <param name="loggedInUserId"></param>
        /// <param name="role">The role.</param>
        /// <returns></returns>
        public DbOperationResult<Role> SaveRolePrivileges(int loggedInUserId, Role role)
        {
            DbOperationResult<Role> result = new DbOperationResult<Role>();

            using (CmsEntities cee = new CmsEntities())
            {
                var loggedInUserName = (from x in cee.Users where x.Id == loggedInUserId select x.FirstName + " " + x.LastName).FirstOrDefault();

                //delete all current privileges and categories for the role

                cee.DeleteWhere<RolePrivilege>(cee, x => x.RoleId == role.Id);
                cee.DeleteWhere<RoleApprovalCategory>(cee, x => x.RoleId == role.Id);

                //Update role
                //Check if the Role exists
                var originalRole = (from x in cee.Roles where x.Id == role.Id select x).FirstOrDefault();

                if (originalRole == null)
                {
                    //Add new Role
                    role.RolePrivileges = null;
                    role.LastModified = String.Format("Last modified {0} by {1}", DateTime.Now, loggedInUserName);
                    originalRole = cee.Roles.Add(role);
                }
                else
                {
                    //Update Role
                    originalRole.Name = role.Name;
                    originalRole.Description = role.Description;
                    originalRole.IsKeyStakeholder = role.IsKeyStakeholder;
                    originalRole.LastModified = String.Format("Last modified {0} by {1}", DateTime.Now, loggedInUserName);
                }

                cee.SaveChanges();

                //Assignt RoleApprovalCategories

                var k = (from x in role.RoleApprovalCategories where x.IsDefault select x).Count();

                if (k > 1)
                {
                    result.ServerErrorMessages.Add("Only one role per category should be the default.");
                    return result;
                }

                foreach (var roleApprovalCategory in role.RoleApprovalCategories)
                {
                    originalRole.RoleApprovalCategories.Add(new RoleApprovalCategory
                    {
                        RoleId = originalRole.Id,
                        IssueCategoryId = roleApprovalCategory.IssueCategoryId,
                        IsDefault = roleApprovalCategory.IsDefault
                    });
                }

                //Assign privileges
                foreach (var rolePrivilege in role.RolePrivileges)
                {
                    originalRole.RolePrivileges.Add(rolePrivilege);
                }

                cee.SaveChanges();

                //saves the IsKeyStakeholder and othe name,desc properties
                role = SaveRole(role);

                role = (from x in cee.Roles
                                     .Include("RolePrivileges")
                                     .Include("RolePrivileges.SecurityObject")
                                     .Include("RolePrivileges.Privilege")
                        where x.Id == role.Id
                        select x).FirstOrDefault();

                result.EntityResult = role;

                return result;
            }
        }
Exemplo n.º 4
0
        public Role SaveRole(Role role)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                Role dbRole = (from x in cee.Roles where x.Name == role.Name select x).FirstOrDefault();

                if (dbRole != null)
                {
                    cee.Entry(dbRole).CurrentValues.SetValues(role);
                }
                else
                {
                    cee.Roles.Add(role);
                }
                cee.SaveChanges();
            }
            return role;
        }
Exemplo n.º 5
0
        private void Save()
        {
            List<RolePrivilege> rolePrivileges = new List<RolePrivilege>();

            //Add only privileges that have access
            foreach (var mRolePrivilegeViewModel in mRolePrivilegesViewModel)
            {
                if (mRolePrivilegeViewModel.HasAccess)
                {
                    mRolePrivilegeViewModel.RolePrivilege.Privilege = null;
                    mRolePrivilegeViewModel.RolePrivilege.Role = null;
                    mRolePrivilegeViewModel.RolePrivilege.SecurityObject = null;

                    rolePrivileges.Add(mRolePrivilegeViewModel.RolePrivilege);
                }
            }

            mRole.RolePrivileges.Clear();
            mRole.RolePrivileges = rolePrivileges;

            //Update Role privileges for this role
            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.SaveRolePrivilegesCompleted += (s1, e1) =>
                                                                   {

                                                                       if (e1.Result.HasErrors)
                                                                       {
                                                                           var errorDialog = new PopupDialog(PopupDialogType.Error, Utils.DisplayErrorMessages(e1.Result.ServerErrorMessages));
                                                                           errorDialog.Show();
                                                                           return;
                                                                       }

                                                                       mRole = e1.Result.EntityResult;

                                                                       if (CMS.User.RoleId == mRole.Id)
                                                                       {
                                                                           //Update the role if the user has the same role assigned
                                                                           CMS.User.Role = mRole;
                                                                       }

                                                                       var existingRole = (from x in CMS.Cache.Roles where x.Id == mRole.Id select x).FirstOrDefault();
                                                                       if (existingRole != null)
                                                                       {
                                                                           //Update role
                                                                           CommonUtils.CloneObject(existingRole, mRole, "Id");
                                                                       }
                                                                       else
                                                                       {
                                                                           //Add new role to the Cache
                                                                           CMS.Cache.Roles.Add(mRole);
                                                                       }
                                                                       Utils.SetEffectivePrivileges();
                                                                       //Close the dialog
                                                                       DialogResult = true;
                                                                   };

            cmsWebServiceClient.SaveRolePrivilegesAsync(CMS.User.Id, mRole);
        }
        public void LoadModel()
        {
            Roles = new List<Role>();
            CMS.Cache.Roles.ForEach( x=> Roles.Add(x));
            Role allRole = new Role{Id = -1, Name = "All"};
            Roles.Insert(0,allRole);
            mSelectedRole = allRole;

            var getDistributionsTask = DatabaseLoader.GetDistributions("Issues");
            var getDistributionUsersDisplayModelTask = DatabaseLoader.GetDistributionUsersDisplayModel();

            List<Task> tasks = new List<Task>();
            tasks.Add(getDistributionsTask);
            tasks.Add(getDistributionUsersDisplayModelTask);

            Task.Factory.ContinueWhenAll(tasks.ToArray(), x =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    mDistributions = getDistributionsTask.Result;

                    Users = new ObservableCollection<DistributionUserDisplayModel>(getDistributionUsersDisplayModelTask.Result);
                    RaisePropertyChanged("Users");

                    Loaded(this, true);
                });
            });
        }
Exemplo n.º 7
0
        public void ImportRoles()
        {
            mForm.AddMessage(MessageType.Info, "-------------------- Importing Roles --------------------");
            List<SecurityLevel> securityLevels = (from x in mOldIssuesDataContext.SecurityLevels select x).ToList();

            List<Role> roles = new List<Role>();

            foreach (var securityLevel in securityLevels)
            {
                Role newRole = new Role()
                {
                    Name = securityLevel.Name,
                    Description = securityLevel.Description,
                    DefaultIssueCategoryId = securityLevel.DefaultCategoryId.HasValue ? securityLevel.DefaultCategoryId.Value : 2
                };

                var roleExist = (from x in mCee.Roles where x.Name == newRole.Name select x).FirstOrDefault();

                if (roleExist == null)
                {
                    string message = String.Format("Adding Role '{0}'", newRole.Name);
                    mForm.AddMessage(MessageType.Info, message);
                    mCee.Roles.AddObject(newRole);
                }
                else
                {
                    string message = String.Format("Role '{0}' already exist, skipping", roleExist.Name);
                    mForm.AddMessage(MessageType.Warning, message);
                }
            }
            mCee.SaveChanges();
        }
Exemplo n.º 8
0
        private void GetRole(int roleId)
        {
            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            EventHandler<GetRoleCompletedEventArgs> fetchCompleted = null;
            fetchCompleted =
                (s1, eventArgs) =>
                {
                    mRole = eventArgs.Result;
                    if (ViewModelLoaded != null)
                        ViewModelLoaded();
                };

            cmsWebServiceClient.GetRoleCompleted += fetchCompleted;
            cmsWebServiceClient.GetRoleAsync(roleId);
        }