Example #1
0
        public void AddSongToList(int listId, int songId, string notes)
        {
            PermissionContext.VerifyPermission(PermissionToken.EditProfile);

            HandleTransaction(session =>
            {
                var list  = session.Load <SongList>(listId);
                var items = session.Query <SongInList>().Where(s => s.List.Id == listId);
                int order = 1;

                if (items.Any())
                {
                    order = items.Max(s => s.Order) + 1;
                }

                EntryPermissionManager.VerifyEdit(PermissionContext, list);

                var song = session.Load <Song>(songId);

                var link = list.AddSong(song, order, notes);
                session.Save(link);

                SysLog($"added {song} to {list}");
            });
        }
Example #2
0
        public void MoveToTrash(int listId)
        {
            PermissionContext.VerifyPermission(PermissionToken.EditProfile);

            HandleTransaction(ctx =>
            {
                var user = GetLoggedUser(ctx);
                var list = ctx.Load <SongList>(listId);

                ctx.AuditLogger.SysLog($"deleting {list.ToString()}");

                EntryPermissionManager.VerifyEdit(PermissionContext, list);

                var archivedVersions = list.ArchivedVersionsManager.Versions;
                ctx.DeleteAll(archivedVersions);
                list.ArchivedVersionsManager.Versions.Clear();

                var activityEntries = ctx.Query <SongListActivityEntry>().Where(a => a.Entry.Id == listId).ToArray();
                ctx.DeleteAll(activityEntries);

                ctx.Delete(list);

                ctx.AuditLogger.AuditLog($"deleted {list.ToString()}", user);
            });
        }
Example #3
0
        public void DeleteSongList(int listId)
        {
            PermissionContext.VerifyPermission(PermissionToken.EditProfile);

            HandleTransaction(session => {
                var user = GetLoggedUser(session);
                var list = session.Load <SongList>(listId);

                EntryPermissionManager.VerifyEdit(PermissionContext, list);

                session.Delete(list);

                AuditLog(string.Format("deleted {0}", list.ToString()), session, user);
            });
        }
Example #4
0
        public void PostPVs(int id, PVContract[] pvs)
        {
            queries.HandleTransaction(ctx => {
                var song = ctx.Load(id);

                EntryPermissionManager.VerifyEdit(userPermissionContext, song);

                var diff = new SongDiff();

                var pvDiff = queries.UpdatePVs(ctx, song, diff, pvs);

                if (pvDiff.Changed)
                {
                    var logStr = string.Format("updated PVs for song {0}", entryLinkFactory.CreateEntryLink(song)).Truncate(400);

                    queries.Archive(ctx, song, diff, SongArchiveReason.PropertiesUpdated, string.Empty);
                    ctx.Update(song);
                    ctx.AuditLogger.AuditLog(logStr);
                }
            });
        }
Example #5
0
 protected void VerifyEntryEdit(IEntryWithStatus entry)
 {
     EntryPermissionManager.VerifyEdit(PermissionContext, entry);
 }
Example #6
0
        public int UpdateSongList(SongListForEditContract contract, UploadedFileContract uploadedFile)
        {
            ParamIs.NotNull(() => contract);

            PermissionContext.VerifyPermission(PermissionToken.EditProfile);

            return(repository.HandleTransaction(ctx => {
                var user = GetLoggedUser(ctx);
                SongList list;

                if (contract.Id == 0)
                {
                    list = CreateSongList(ctx, contract, uploadedFile);
                }
                else
                {
                    list = ctx.Load(contract.Id);
                    var diff = new SongListDiff();

                    EntryPermissionManager.VerifyEdit(PermissionContext, list);

                    if (list.Description != contract.Description)
                    {
                        diff.Description.Set();
                        list.Description = contract.Description ?? string.Empty;
                    }

                    if (list.Name != contract.Name)
                    {
                        diff.Name.Set();
                        list.Name = contract.Name;
                    }

                    if (EntryPermissionManager.CanManageFeaturedLists(PermissionContext) && list.FeaturedCategory != contract.FeaturedCategory)
                    {
                        diff.FeaturedCategory.Set();
                        list.FeaturedCategory = contract.FeaturedCategory;
                    }

                    if (list.EventDate != contract.EventDate)
                    {
                        diff.SetChanged(SongListEditableFields.EventDate);
                        list.EventDate = contract.EventDate;
                    }

                    if (list.Status != contract.Status)
                    {
                        diff.Status.Set();
                        list.Status = contract.Status;
                    }

                    var songDiff = list.SyncSongs(contract.SongLinks, c => ctx.OfType <Song>().Load(c.Song.Id));

                    if (songDiff.Changed)
                    {
                        diff.Songs.Set();
                    }

                    ctx.OfType <SongInList>().Sync(songDiff);

                    if (uploadedFile != null)
                    {
                        diff.Thumbnail.Set();
                        SetThumb(list, uploadedFile);
                    }

                    ctx.Update(list);

                    ctx.AuditLogger.AuditLog(
                        string.Format("updated song list {0} ({1})", entryLinkFactory.CreateEntryLink(list), diff.ChangedFieldsString), user);

                    var archived = Archive(ctx, list, diff, EntryEditEvent.Updated, contract.UpdateNotes);

                    if (list.FeaturedList)
                    {
                        AddEntryEditedEntry(ctx.OfType <ActivityEntry>(), list, EntryEditEvent.Updated, archived);
                    }
                }

                return list.Id;
            }));
        }