public bool AddRole(NewRole role)
 {
     if (role != null)
     { 
         Role r = this.repository.GetRole(role.RoleName);
         if (r != null)
             role.AddError("Rola o podanej nazwie już istnieje");
         if (role.IsValid)
         {
             this.repository.AddRole(role);
             return true;
         }
         return false;
     }
     return false;
 }
        public void AddRole(NewRole role)
        {
            if (role != null)
            {
                Role r = new Role()
                {
                    Name = role.RoleName
                };

                foreach (Privilage p in role.Privilages)
                {
                    r.Privilages.Add(p);
                }

                SPDatabase.DB.Roles.AddObject(r);
                SPDatabase.DB.SaveChanges();
            }
        }
Example #3
0
        private void btnAddRole_Click(object sender, EventArgs e)
        {
            NewRole role = new NewRole()
            {
                RoleName = tbNewRoleName.Text
            };

            List<string> list = clbPrivilages.CheckedItems.Cast<string>().ToList<string>();
            if (list != null && list.Count > 0)
            {
                List<Privilage> privilages = new List<Privilage>();
                foreach (string name in list)
                {
                    Privilage p = RoleController.Instance.GetPrivilage(name);
                    if (p != null)
                        privilages.Add(p);
                }
                role.Privilages = privilages.AsEnumerable();
            }
            else
                role.Privilages = null;

            if (!RoleController.Instance.AddRole(role))
            {
                string errors = string.Empty;
                foreach (string error in role.Errors)
                {
                    errors = errors + error + "\n";
                }
                lblValidation.Text = errors;
            }
            else
            {
                changes = true;
                FillWithRoles();
                Clear();
            }
        }