public static ProfileDetails ToProfileDetails(this ProfileViewModel profileViewModel)
        {
            var profileDetails = new ProfileDetails();
            AutoMapper.Mapper.Map(profileViewModel, profileDetails);
            
            profileDetails.ArePdfs = profileViewModel.SelectedPdfAreaTypes != null &&
                                     profileViewModel.SelectedPdfAreaTypes.Any();


            if(profileViewModel.ProfileUsers != null)
            {
                profileDetails.UserPermissions = profileViewModel.ProfileUsers
                        .Select(user => new UserGroupPermissions()
                        {
                            UserId = user.Id,
                            FpmUser = new FpmUser()
                            {
                                Id = user.Id, 
                                DisplayName = user.Name
                            }
                        });
            }
            
            if (profileViewModel.SelectedPdfAreaTypes != null)
            {
                profileDetails.PdfAreaTypes = profileViewModel.SelectedPdfAreaTypes
                    .Select(areaType => new AreaType() {Id = areaType.Id});
            }
            return profileDetails;
        }
        public void UpdateProfile(ProfileDetails profileDetails)
        {
            try
            {
                transaction = CurrentSession.BeginTransaction();

                CurrentSession.Delete("from UserGroupPermissions where profileId = " + profileDetails.Id);

                CurrentSession.Update(profileDetails);

                if (profileDetails.UserPermissions != null)
                    profileDetails.UserPermissions.ForEach(u =>
                    {
                        u.ProfileId = profileDetails.Id;
                        CurrentSession.Save(u);
                    });

                CurrentSession.GetNamedQuery("Delete_ProfilePDFs")
                    .SetParameter("ProfileId", profileDetails.Id)
                    .ExecuteUpdate();

                if (profileDetails.PdfAreaTypes != null)
                {
                    profileDetails.PdfAreaTypes.ForEach(a => CurrentSession.GetNamedQuery("Insert_ProfilePDFs")
                        .SetParameter("ProfileId", profileDetails.Id)
                        .SetParameter("AreaTypeId", a.Id)
                        .ExecuteUpdate());
                }
                transaction.Commit();
            }
            catch (Exception exception)
            {
                HandleException(exception);
            }
        }
        public int CreateProfile(ProfileDetails profileDetails)
        {
            var newProfileId = ProfileIds.Undefined;

            try
            {
                transaction = CurrentSession.BeginTransaction();

                newProfileId = (int)CurrentSession.Save(profileDetails);

                profileDetails.UserPermissions.ToList()
                        .ForEach(u =>
                        {
                            u.ProfileId = newProfileId;
                            CurrentSession.Save(u);
                        });

                transaction.Commit();
            }
            catch (Exception exception)
            {
                HandleException(exception);
            }

            return newProfileId;
        }
        public void TestExtraFilesStringsConvertedToNulls()
        {
            var details = new ProfileDetails
            {
                ExtraJsFiles = string.Empty,
                ExtraCssFiles = string.Empty
            };

            ProfileDetailsCleaner.CleanUserInput(details);

            Assert.IsNull(details.ExtraJsFiles);
            Assert.IsNull(details.ExtraCssFiles);
        }
        public void TestEmptyAreaStringsConvertedToNulls()
        {
            var details = new ProfileDetails
            {
                AreasIgnoredEverywhere = string.Empty,
                AreasIgnoredForSpineChart = string.Empty
            };

            ProfileDetailsCleaner.CleanUserInput(details);

            Assert.IsNull(details.AreasIgnoredEverywhere);
            Assert.IsNull(details.AreasIgnoredForSpineChart);
        }
        public void TestWhitespaceRemoved()
        {
            var details = new ProfileDetails
            {
                Name = " b ",
                AreasIgnoredEverywhere = " a , b ",
                AreasIgnoredForSpineChart = " c , d "
            };

            ProfileDetailsCleaner.CleanUserInput(details);

            Assert.AreEqual("b", details.Name);
            Assert.AreEqual("a,b", details.AreasIgnoredEverywhere);
            Assert.AreEqual("c,d", details.AreasIgnoredForSpineChart);
        }
        public static void CleanUserInput(ProfileDetails profileDetails)
        {
            profileDetails.Name = Clean(profileDetails.Name);

            profileDetails.AreasIgnoredForSpineChart = 
                CleanAreasString(profileDetails.AreasIgnoredForSpineChart);

            profileDetails.AreasIgnoredEverywhere =
                CleanAreasString(profileDetails.AreasIgnoredEverywhere);

            profileDetails.ExtraJsFiles =
                CleanAreasString(profileDetails.ExtraJsFiles);

            profileDetails.ExtraCssFiles =
                CleanAreasString(profileDetails.ExtraCssFiles);
        }
        public void ToProfileViewModel_Returns_Model_WithSameValues()
        {
            // Arrange
            var profileDetail = new ProfileDetails()
            {
                Id = 5,
                Name = "Test Profile",
                ContactUserId = 10
            };

            // Act
            var result = profileDetail.ToProfileViewModel();

            // Assert
            Assert.IsTrue(result.ContactUserId == profileDetail.ContactUserId &&
                          result.Id == profileDetail.Id &&
                          result.Name == profileDetail.Name);
        }