Example #1
0
        public string[] DeletePhotos(DeletePhotoParameters[] photos, string albumId)
        {
            string[] albumCovers = new string[] { };
            ServiceSupport.AuthorizeAndExecute(() =>
            {
                var album = AlbumRepository.FindAlbumById(albumId);
                if (album == null)
                {
                    throw new FaultException <ServerFault>(new ServerFault()
                    {
                        FaultCode = ServerFaultCode.Generic
                    },
                                                           new FaultReason("No album with Id " + albumId + " was found."));
                }

                var photoIds = photos.Select(x => x.PhotoId);

                CloudTaskManager.PublishTask(storage =>
                {
                    foreach (var photoFile in photos.Select(x => x.FileName))
                    {
                        storage.DeletePhoto(photoFile, albumId);
                    }
                });

                if (HttpContext.Current.IsSuperAdminLoggedIn())
                {
                    PhotoRepository.DeletePhotos(photoIds, albumId);
                    albumCovers = AlbumRepository.UpdateCovers(album);
                }
                else
                {
                    // Only album author can delete photos
                    if (!HttpContext.Current.IsUserLoggedIn(album.CreatedBy))
                    {
                        throw new FaultException <ServerFault>(new ServerFault()
                        {
                            FaultCode = ServerFaultCode.NotAuthroized
                        },
                                                               new FaultReason("Photos must only be deleted by the author of the album they belong to."));
                    }
                    else
                    {
                        // Delete photos by selected IDs and album ID
                        PhotoRepository.DeletePhotos(photoIds, albumId);
                        albumCovers = AlbumRepository.UpdateCovers(album);
                    }
                }
            });
            return(albumCovers);
        }
Example #2
0
 public void DeleteAlbum(string albumId)
 {
     ServiceSupport.AuthorizeAndExecute(() =>
     {
         if (HttpContext.Current.IsSuperAdminLoggedIn())
         {
             // TODO: should we consider doing this cloud operation in another thread? How about a background worker?
             CloudTaskManager.PublishTask(storage =>
             {
                 storage.DeleteAlbum(albumId);
             });
             AlbumRepository.DeleteAlbum(albumId);
         }
         else
         {
             var album = AlbumRepository.FindAlbumById(albumId);
             if (album == null)
             {
                 throw new FaultException <ServerFault>(new ServerFault()
                 {
                     FaultCode = ServerFaultCode.Generic
                 },
                                                        new FaultReason("No album with Id " + albumId + " was found."));
             }
             // Only album author can delete photos
             if (!HttpContext.Current.IsUserLoggedIn(album.CreatedBy))
             {
                 throw new FaultException <ServerFault>(new ServerFault()
                 {
                     FaultCode = ServerFaultCode.NotAuthroized
                 },
                                                        new FaultReason("Album must only be deleted by the author."));
             }
             else
             {
                 // Delete photos by selected IDs and album ID
                 CloudTaskManager.PublishTask(storage =>
                 {
                     storage.DeleteAlbum(albumId);
                 });
                 AlbumRepository.DeleteAlbum(albumId);
             }
         }
     });
 }
Example #3
0
        public void UpdateAlbum(string name, string description, string albumId)
        {
            ServiceSupport.AuthorizeAndExecute(() =>
            {
                var album = AlbumRepository.FindAlbumById(albumId);
                if (album == null)
                {
                    throw new FaultException <ServerFault>(new ServerFault()
                    {
                        FaultCode = ServerFaultCode.Generic
                    },
                                                           new FaultReason("No album with Id " + albumId + " was found."));
                }

                album.Name        = name;
                album.Description = description;

                if (HttpContext.Current.IsSuperAdminLoggedIn())
                {
                    AlbumRepository.SaveAlbum(album);
                }
                else
                {
                    if (!HttpContext.Current.IsUserLoggedIn(album.CreatedBy))
                    {
                        throw new FaultException <ServerFault>(new ServerFault()
                        {
                            FaultCode = ServerFaultCode.NotAuthroized
                        },
                                                               new FaultReason("Album must only be edited by the author."));
                    }
                    else
                    {
                        AlbumRepository.SaveAlbum(album);
                    }
                }
            });
        }