public bool UpdateProfileCollection(int profileCollectionId, string assignedProfilesToUpdate, string collectionNameToUpdate, string collectionSkinTitleToUpdate)
        {

            try
            {
                transaction = CurrentSession.BeginTransaction();
                var profileCollection = new ProfileCollection()
                {
                    Id = profileCollectionId,
                    CollectionName = collectionNameToUpdate,
                    CollectionSkinTitle = collectionSkinTitleToUpdate
                };

                CurrentSession.Delete("from ProfileCollectionItem where ProfileCollectionId = " + profileCollectionId);

                CurrentSession.Update(profileCollection);

                if (!string.IsNullOrEmpty(assignedProfilesToUpdate))
                {
                    foreach (var assignedProfile in assignedProfilesToUpdate.Split(','))
                    {
                        var assignedProfileId = assignedProfile.Split('~')[0];
                        var showDomain = assignedProfile.Split('~')[1] == "true";

                        CurrentSession.Save(new ProfileCollectionItem()
                        {
                            ProfileCollectionId = profileCollectionId,
                            ProfileId = Convert.ToInt32(assignedProfileId),
                            DisplayDomains = showDomain
                        });

                    }
                }

                transaction.Commit();
                return true;
            }
            catch (Exception exception)
            {
                HandleException(exception);
            }
            return false;
        }
        public int CreateProfileCollection(ProfileCollection profileCollection, string assignedProfiles)
        {
            try
            {
                transaction = CurrentSession.BeginTransaction();

                var profileCollectionId = (int)CurrentSession.Save(profileCollection);

                if (!string.IsNullOrEmpty(assignedProfiles))
                {
                    assignedProfiles.Split(',')
                        .ForEach(profileId =>
                            CurrentSession.Save(new ProfileCollectionItem()
                            {
                                ProfileCollectionId = profileCollectionId,
                                ProfileId = Convert.ToInt32(profileId)
                            })
                        );
                }

                transaction.Commit();
                return profileCollectionId;
            }
            catch (Exception exception)
            {
                HandleException(exception);
            }
            return -1;
        }
        public ActionResult InsertProfileCollection(ProfileCollection profileCollection, string assignedProfiles)
        {
            var newProfileCollection = new ProfileCollection
            {
                CollectionName = profileCollection.CollectionName,
                CollectionSkinTitle = profileCollection.CollectionSkinTitle
            };

            _profileRepository.CreateProfileCollection(newProfileCollection, assignedProfiles);

            return RedirectToAction("ManageProfileCollections");
        }
        public ActionResult CreateProfileCollection()
        {
            //Get all profiles
            IOrderedEnumerable<ProfileDetails> allProfiles = _reader.GetProfiles().OrderBy(x => x.Name);
            var profileCollection = new ProfileCollection { ProfileCollectionItems = new List<ProfileCollectionItem>() };

            foreach (ProfileDetails profileDetails in allProfiles)
            {
                profileCollection.ProfileCollectionItems.Add(new ProfileCollectionItem { profileDetails = profileDetails });
            }

            if (HttpContext.Request.UrlReferrer != null)
                profileCollection.ReturnUrl = HttpContext.Request.UrlReferrer.ToString();

            return View("CreateProfileCollection", profileCollection);
        }
        public void UpdateProfileCollection_Update_a_Collection()
        {
            // Arrange
            const string assignedProfilesToInsert = @"53,39";
            const string assignedProfilesToUpdate = @"53~true,39~false,72~false";

            var randomNumber = new Random().Next();

            var profileCollectionToInsert = new ProfileCollection()
            {
                CollectionName = "Test Collection " + randomNumber,
                CollectionSkinTitle = "Test Skin" + randomNumber
            };


            var collectionNameToUpdate = "Test Update Collection " + randomNumber;
            var collectionSkinTitleToUpdate = "Test Update Skin" + randomNumber;

            // Act
            var profileCollectionid = _profileRepository.CreateProfileCollection(profileCollectionToInsert,
              assignedProfilesToInsert);
            _profileRepository.Dispose();

            _profileRepository.OpenSession();


            var result = _profileRepository.UpdateProfileCollection(profileCollectionid, assignedProfilesToUpdate,
                collectionNameToUpdate, collectionSkinTitleToUpdate);

            // Assert
            Assert.IsTrue(result == true);
        }
        public void CreateProfileCollection_Creates_EmptyCollection_For_NoAssignedProfiles_()
        {
            // Arrange
            const string assignedProfiles = "";
            var randomNumber = new Random().Next();
            var profileCollection = new ProfileCollection()
            {
                CollectionName = "Test Collection " + randomNumber,
                CollectionSkinTitle = "Test Skin title" + randomNumber
            };

            // Act
            var result = _profileRepository.CreateProfileCollection(profileCollection, assignedProfiles);

            // Assert
            Assert.IsTrue(result > 1);
        }