// **************************************
        // AddToSongsBalance
        // **************************************
        public static void AddToSongsBalance(this User user)
        {
            using (var ctx = new SongSearchContext()) {

                ctx.AddToSongsBalance(user);
                ctx.SaveChanges();

            }
        }
        // **************************************
        // SaveCatalog
        // **************************************
        private CatalogUploadState SaveCatalog(CatalogUploadState state)
        {
            System.Diagnostics.Debug.Write("Step5");

            var user = Account.User();
            // Save/create Catalog
            if (user.IsAtLeastInRole(Roles.Admin) && !user.MyBalances().NumberOfSongs.IsAtTheLimit) {

                using (var ctx = new SongSearchContext()) {

                    var catalog = ctx.Catalogs.SingleOrDefault(c => c.CatalogName.ToUpper() == state.CatalogName) ??
                        new Catalog() {
                            CatalogName = state.CatalogName,
                            CreatedByUserId = user.UserId,
                            CreatedOn = DateTime.Now
                        };

                    if (catalog.CatalogId == 0) {

                        ctx.Catalogs.AddObject(catalog);
                        //DataSession.CommitChanges();

                        //Make current user an admin
                        var userCatalog = new UserCatalogRole() {
                            UserId = user.UserId,
                            CatalogId = catalog.CatalogId,
                            RoleId = (int)Roles.Admin
                        };
                        ctx.UserCatalogRoles.AddObject(userCatalog);

                        //Make parent user an admin
                        if (user.ParentUserId.HasValue) {
                            var parentUserCatalog =
                                //DataSession.Single<UserCatalogRole>(
                                //    x => x.UserId == user.ParentUserId.Value &&
                                //        x.CatalogId == catalog.CatalogId &&
                                //        x.RoleId == (int)Roles.Admin
                                //        ) ??
                                new UserCatalogRole() {
                                    UserId = user.ParentUserId.Value,
                                    CatalogId = catalog.CatalogId,
                                    RoleId = (int)Roles.Admin
                                };
                            ctx.UserCatalogRoles.AddObject(parentUserCatalog);
                        }

                        //Make plan user an admin
                        if (!user.IsPlanOwner && user.PlanUserId != user.ParentUserId.GetValueOrDefault()) {
                            var planUserCatalog =
                                //DataSession.Single<UserCatalogRole>(
                                //    x => x.UserId == user.PlanUserId &&
                                //        x.CatalogId == catalog.CatalogId &&
                                //        x.RoleId == (int)Roles.Admin
                                //        ) ??
                                new UserCatalogRole() {
                                    UserId = user.PlanUserId,
                                    CatalogId = catalog.CatalogId,
                                    RoleId = (int)Roles.Admin
                                };
                            ctx.UserCatalogRoles.AddObject(planUserCatalog);
                        }

                        // defer?
                        ctx.SaveChanges();
                    }

                    state.CatalogId = catalog.CatalogId;
                    state.CatalogName = catalog.CatalogName.ToUpper();

                    // Save Content
                    var content = App.IsLicensedVersion ?
                        state.Content.Take(user.MyBalances().NumberOfSongs.IsGoodFor(state.Content.Count())).ToList() :
                        state.Content;

                    foreach (var itm in content) {

                        itm.CatalogId = state.CatalogId;
                        itm.CreatedByUserId = user.UserId;
                        itm.CreatedOn = DateTime.Now;
                        itm.LastUpdatedByUserId = user.UserId;
                        itm.LastUpdatedOn = DateTime.Now;
                        //itm.IsMediaOnRemoteServer = false;

                        itm.Title = itm.Title.AsEmptyIfNull();//.CamelCase();//.ToUpper();
                        itm.Artist = itm.Artist.AsEmptyIfNull();//.CamelCase();//.ToUpper();
                        itm.RecordLabel = itm.RecordLabel.AsEmptyIfNull();//.CamelCase();//.ToUpper();
                        itm.ReleaseYear = itm.ReleaseYear.GetValueOrDefault().AsNullIfZero();
                        itm.Notes = itm.Notes;

                        var full = itm.UploadFiles.SingleOrDefault(f => f.FileMediaVersion == MediaVersion.Full);
                        foreach (var version in ModelEnums.MediaVersions()) {

                            var upl = itm.UploadFiles.SingleOrDefault(f => f.FileMediaVersion == version);
                            if (upl != null) {

                                var file = new FileInfo(upl.FilePath);
                                var id3 = ID3Writer.NormalizeTag(upl.FilePath, itm);

                                var media = new ContentMedia() {

                                    MediaVersion = (int)version,
                                    MediaType = "mp3",
                                    MediaSize = file.Length,
                                    MediaLength = id3.MediaLength,
                                    MediaDate = file.GetMediaDate(),
                                    MediaBitRate = id3.GetBitRate(file.Length)
                                };

                                media.IsRemote = false;

                                itm.ContentMedia.Add(media);
                            }

                        }
                        ctx.Contents.AddObject(itm);
                        ctx.AddToSongsBalance(user);
                        ctx.SaveChanges();

                        if (itm.ContentId > 0) {
                            foreach (var file in itm.UploadFiles) {
                                MediaService.SaveContentMedia(file.FilePath, itm.Media(file.FileMediaVersion));
                            }
                        }

                    }

                }
            }

            SessionService.Session().InitializeSession(true);
            CacheService.InitializeApp(true);

            return state;
        }