示例#1
0
        public static string Serialize(VCard vcard)
        {
            var builder = new StringBuilder();

            builder.Append(VersionProcessor.Serialize(vcard));
            builder.Append(FormattedNameProcessor.Serialize(vcard));
            builder.Append(NameProcessor.Serialize(vcard));
            builder.Append(BirthDayProcessor.Serialize(vcard));
            builder.Append(MailerProcessor.Serialize(vcard));
            builder.Append(TitleProcessor.Serialize(vcard));
            builder.Append(RoleProcessor.Serialize(vcard));
            builder.Append(TimeZoneInfoProcessor.Serialize(vcard));

            builder.Append(LogoProcessor.Serialize(vcard));
            builder.Append(PhotoProcessor.Serialize(vcard));

            builder.Append(NoteProcessor.Serialize(vcard));
            builder.Append(LastRevisionProcessor.Serialize(vcard));
            builder.Append(UrlProcessor.Serialize(vcard));
            builder.Append(UidProcessor.Serialize(vcard));
            builder.Append(OrganizationProcessor.Serialize(vcard));
            builder.Append(GeographyProcessor.Serialize(vcard));

            builder.Append(AddressesProcessor.Serialize(vcard));
            builder.Append(DeliveryAddressProcessor.Serialize(vcard));
            builder.Append(TelephonesProcessor.Serialize(vcard));
            builder.Append(EmailsProcessor.Serialize(vcard));
            builder.Append(ExtensionsProcessor.Serialize(vcard));

            return(builder.ToString());
        }
        public User GetUserForUsername(string _Username)
        {
            var data = UserProcessor.SelectUserForUsername(_Username);

            data = UserProcessor.SelectUserWithRoles(data.UserId);

            var user = new User
            {
                UserId       = data.UserId,
                Username     = data.Username,
                FirstName    = data.FirstName,
                LastName     = data.LastName,
                EmailAddress = data.Email,
                PhoneNumber  = data.PhoneNo,
                Password     = data.Password,
            };

            foreach (var userRoleData in data.UserRoles)
            {
                var userRole = new UserRole( );
                userRole.RoleId = userRoleData.RoleId;
                userRole.UserId = userRoleData.UserId;
                userRole.User   = user;

                var roleData = RoleProcessor.SelectRoleWithPermissions(userRoleData.RoleId);
                var role     = new Role( );
                role.RoleId = roleData.RoleId;
                role.Name   = roleData.Name;
                foreach (var rolePermissionData in roleData.RolePermissions)
                {
                    var rolePermission = new RolePermission( );
                    rolePermission.RoleId       = rolePermissionData.RoleId;
                    rolePermission.PermissionId = rolePermissionData.RoleId;
                    rolePermission.Role         = role;

                    var permissionData = PermissionProcessor.SelectPermission(rolePermissionData.PermissionId);
                    var permission     = new Permission(permissionData);

                    rolePermission.Permission = permission;

                    role.RolePermissions.Add(rolePermission);
                }
                userRole.Role = role;
                user.UserRoles.Add(userRole);
            }

            return(user);
        }
        public void GetUsers( )
        {
            var userData = UserProcessor.SelectUsers( );

            Users = new List <User>( );
            foreach (var row in userData)
            {
                var user = new User
                {
                    UserId       = row.UserId,
                    Username     = row.Username,
                    FirstName    = row.FirstName,
                    LastName     = row.LastName,
                    EmailAddress = row.Email,
                    PhoneNumber  = row.PhoneNo,
                    Password     = row.Password
                };
                var userRoleModel = UserRoleProcessor.LoadRolesForUser(row.UserId);
                foreach (var ur in userRoleModel)
                {
                    var roleModel = RoleProcessor.SelectRole(ur.RoleId);
                    var role      = new Role
                    {
                        RoleId = roleModel.RoleId,
                        Name   = roleModel.Name
                    };
                    var userRole = new UserRole
                    {
                        UserRoleId = ur.UserRoleId,
                        UserId     = ur.UserId,
                        RoleId     = ur.RoleId,
                        User       = user,
                        Role       = role
                    };
                    user.UserRoles.Add(userRole);
                }
                Users.Add(user);
            }
        }
        public List <Role> GetRoles(int id = 0)
        {
            var data = RoleProcessor.SelectRoles( );

            Roles = new List <Role>( );

            foreach (var row in data)
            {
                var role = new Role( )
                {
                    RoleId = row.RoleId,
                    Name   = row.Name,
                };

                if (id == role.RoleId)
                {
                    Role = role;
                }
                Roles.Add(role);
            }

            return(Roles);
        }
        private void UserList_Load(object sender, System.EventArgs e)
        {
            this.RoleComboBox.Items.AddRange(RoleProcessor.GetRoles().ToArray());
            if (this.RoleComboBox.Items.Count == 0)
            {
                this.RoleComboBox.Text = Constants.WarningMessages.NoRoles;
            }
            if (user.IsDeleted)
            {
                NoRadioButton.Checked = true;
            }
            else
            {
                YesRadioButton.Checked = true;
            }
            UsernameTextBox.Text    = user.Username;
            EmailTextBox.Text       = user.Email;
            PhoneNumberTextBox.Text = user.PhoneNumber;
            RoleComboBox.Text       = user.Role.ToString();

            this.PhoneNumberInfoLabel.Visible = false;
            this.EmailInfoLabel.Visible       = false;
            this.UsernameInfoLabel.Visible    = false;
        }
        public List <RolePermission> getRolePermissionByRoleId(int roleId)
        {
            var roleData = RoleProcessor.SelectRoleWithPermissions(roleId);
            var role     = new Role( );

            role.RoleId = roleData.RoleId;
            role.Name   = roleData.Name;
            foreach (var rolePermissionData in roleData.RolePermissions)
            {
                var rolePermission = new RolePermission( );
                rolePermission.RoleId       = rolePermissionData.RoleId;
                rolePermission.PermissionId = rolePermissionData.RoleId;
                rolePermission.Role         = role;

                var permissionData = PermissionProcessor.SelectPermission(rolePermissionData.PermissionId);
                var permission     = new Permission( );
                permission.PermissionId   = permissionData.PermissionId;
                permission.PermissionName = permissionData.PermissionName;
                rolePermission.Permission = permission;

                role.RolePermissions.Add(rolePermission);
            }
            return(role.RolePermissions.ToList( ));
        }
        public ActionResult Save(UserRole _UserRole)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.User))
            {
                return(RedirectToPermissionDenied());
            }

            // Null safe check to prevent crashes.
            if (_UserRole.User == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            try
            {
                if (_UserRole.RoleId <= 0)
                {
                    throw new DataException("No Role selected.");
                }

                var rowsFound = UserRoleProcessor.SelectUserRoleForUserIdAndRoleId(_UserRole.User.UserId, _UserRole.RoleId);
                if (rowsFound > 0)
                {
                    throw new DataException($"User is already assigned this Role.");
                }

                var user = db.GetUser(_UserRole.User.UserId);

                if (user.UserRoles.Any(ur => ur.Role.Name == "Student"))
                {
                    throw new DataException("A User with a Role of Student cannot be assigned additional roles.");
                }

                var role = RoleProcessor.SelectRole(_UserRole.RoleId);

                if (user.UserRoles.Count( ) > 0 && user.UserRoles.Any(ur => ur.Role.Name != "Student") && role.Name == "Student")
                {
                    throw new DataException("A User with an Employee role type cannot be a Student.");
                }


                // Attempt to insert new UserRole to database using data from parameter
                var data = UserRoleProcessor.InsertUserRole(_UserRole.User.UserId, _UserRole.RoleId);
                // Checks if Insert operation was successful. If not throws an error.
                if (data == null)
                {
                    throw new DataException("Role added was invalid.");
                }
            }
            catch (Exception _Ex)
            {
                // Error handling
                ModelState.AddModelError("", $"Unable to save changes due to Error: { _Ex.Message }");
                db.GetUser(_UserRole.User.UserId);
                PopulateRoleDropDownList( );

                return(View(db));
            }

            // Redirects to page where data is reloaded.
            return(Redirect(Request.UrlReferrer.ToString( )));
        }
示例#8
0
 public bool IsRoleValid(string role)
 {
     return(RoleProcessor.GetRoles().Contains(role));
 }