Пример #1
0
        public UserRolesViewModel MapUserRoles(UserProfile user, IList<UserRole> roles)
        {
            if (user == null) return new UserRolesViewModel();
            var view = new UserRolesViewModel
                           {
                               FirstName = user.FirstName,
                               LastName = user.LastName,
                               UserName = user.UserName,
                               Roles = new List<RolesViewModel>()
                           };

            foreach (UserRole role in roles)
            {
                RolesViewModel roleView = Mapper.Map<UserRole, RolesViewModel>(role);
                foreach (UserRole userRole in user.Roles)
                {
                    roleView.IsChecked = userRole.Id == role.Id;

                }
                view.Roles.Add(roleView);

            }

            var selectRoles = new MultiSelectList(view.Roles, "RoleId", "RoleName",
                view.Roles
                .Where(x => x.IsChecked)
                .Select(x =>x.RoleId));

            view.MultiSelectRoles = selectRoles;

            return view;
        }
Пример #2
0
 public string AddUserProfile(UserProfile user)
 {
     if (! _context.UserProfiles.Any(x => x.UserName == user.UserName))
     {
         _context.UserProfiles.Add(user);
         _context.SaveChanges();
         _context.Dispose();
         return string.Empty;
     }
     return "User already exists.";
 }
Пример #3
0
 public string UpdateUserProfile(UserProfile userProfile)
 {
     var user = _context.UserProfiles.FirstOrDefault(x => x.Id == userProfile.Id);
     if (user == null) return "The specified user could not be found.";
     user.Email = userProfile.Email;
     user.FirstName = userProfile.FirstName;
     user.Password = userProfile.Password;
     user.UserName = userProfile.UserName;
     user.AboutMe = userProfile.AboutMe;
     _context.SaveChanges();
     _context.Dispose();
     return string.Empty;
 }
Пример #4
0
 public UserViewModel MapView(UserProfile entity)
 {
     return Mapper.Map<UserProfile, UserViewModel>(entity);
 }
Пример #5
0
        private UserRolesViewModel MapUserToRoles(UserProfile user)
        {
            if (user == null) return new UserRolesViewModel();
            IList<UserRole> roles = _profileUserRepository.GetAllRoles();

            UserRolesViewModel view = _mappingService.MapUserRoles(user, roles);
            return view;
        }