Exemplo n.º 1
0
        private SongList CreateSongList(IDatabaseContext <SongList> ctx, SongListForEditContract contract, UploadedFileContract uploadedFile)
        {
            var user    = GetLoggedUser(ctx);
            var newList = new SongList(contract.Name, user);

            newList.Description = contract.Description ?? string.Empty;
            newList.EventDate   = contract.EventDate;

            if (EntryPermissionManager.CanManageFeaturedLists(permissionContext))
            {
                newList.FeaturedCategory = contract.FeaturedCategory;
            }

            ctx.Save(newList);

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

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

            SetThumb(newList, uploadedFile);

            ctx.Update(newList);

            ctx.AuditLogger.AuditLog(string.Format("created song list {0}", entryLinkFactory.CreateEntryLink(newList)), user);
            var archived = Archive(ctx, newList, new SongListDiff(), EntryEditEvent.Created, contract.UpdateNotes);

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

            return(newList);
        }
Exemplo n.º 2
0
        private SongList CreateSongList(IRepositoryContext <SongList> ctx, SongListForEditContract contract, UploadedFileContract uploadedFile)
        {
            var user    = GetLoggedUser(ctx);
            var newList = new SongList(contract.Name, user);

            newList.Description = contract.Description;

            if (EntryPermissionManager.CanManageFeaturedLists(permissionContext))
            {
                newList.FeaturedCategory = contract.FeaturedCategory;
            }

            ctx.Save(newList);

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

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

            SetThumb(newList, uploadedFile);

            ctx.Update(newList);

            ctx.AuditLogger.AuditLog(string.Format("created song list {0}", entryLinkFactory.CreateEntryLink(newList)), user);
            Archive(ctx, newList, new SongListDiff(), EntryEditEvent.Created);

            return(newList);
        }
Exemplo n.º 3
0
        public SongListEditViewModel(SongListContract contract, IUserPermissionContext permissionContext)
            : this()
        {
            ParamIs.NotNull(() => contract);

            CurrentName      = contract.Name;
            Description      = contract.Description;
            FeaturedCategory = contract.FeaturedCategory;
            Id    = contract.Id;
            Name  = contract.Name;
            Thumb = contract.Thumb;

            CanCreateFeaturedLists = EntryPermissionManager.CanManageFeaturedLists(permissionContext);
        }
Exemplo n.º 4
0
        public SongListEdit(SongListForEditContract contract)
            : this()
        {
            ParamIs.NotNull(() => contract);

            CurrentName      = contract.Name;
            Description      = contract.Description;
            FeaturedCategory = contract.FeaturedCategory;
            Id        = contract.Id;
            Name      = contract.Name;
            SongLinks = contract.SongLinks;

            CanCreateFeaturedLists = EntryPermissionManager.CanManageFeaturedLists(MvcApplication.LoginManager);
        }
Exemplo n.º 5
0
        public SongListEditViewModel(SongListContract contract, IUserPermissionContext permissionContext)
            : this()
        {
            ParamIs.NotNull(() => contract);

            CurrentName      = contract.Name;
            Description      = contract.Description;
            EventDate        = contract.EventDate;
            FeaturedCategory = contract.FeaturedCategory;
            Id     = contract.Id;
            Name   = contract.Name;
            Status = contract.Status;
            Thumb  = contract.Thumb;

            AllowedEntryStatuses   = new [] { EntryStatus.Draft, EntryStatus.Finished };
            CanCreateFeaturedLists = EntryPermissionManager.CanManageFeaturedLists(permissionContext);
        }
Exemplo n.º 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;
            }));
        }
Exemplo n.º 7
0
 public SongListEdit()
 {
     SongLinks = new List <SongInListEditContract>();
     CanCreateFeaturedLists = EntryPermissionManager.CanManageFeaturedLists(MvcApplication.LoginManager);
 }