Exemplo n.º 1
0
        public PhotoComment CreateComment(PhotoComment comment)
        {
            PhotoComment result = null;

            ServiceSupport.AuthorizeAndExecute(() =>
            {
                result = PhotoRepository.CreateComment(comment);
            });
            return(result);
        }
Exemplo n.º 2
0
        public string RequestPhotoUploadTicket(string requestToken)
        {
            string result = null;

            // Only logged-in user can get the ticket
            ServiceSupport.AuthorizeAndExecute(() =>
            {
                result = PhotoUploadTicketPool.GenerateTicket(requestToken);
            });
            return(result);
        }
Exemplo n.º 3
0
        public PagedResult <LogEntry> GetPagedLogs(int pageIndex, int pageSize)
        {
            PagedResult <LogEntry> result = null;

            ServiceSupport.AuthorizeAndExecute(() =>
            {
                result                = new PagedResult <LogEntry>();
                result.Entities       = LogRepository.GetPagedLogs(pageIndex, pageSize).ToList();
                result.TotalItemCount = LogRepository.GetTotalLogCount();
            }, "ktei");
            return(result);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 public void DeleteComment(string commentId)
 {
     ServiceSupport.AuthorizeAndExecute(() =>
     {
         if (HttpContext.Current.IsSuperAdminLoggedIn())
         {
             PhotoRepository.DeleteComment(commentId);
         }
         else
         {
             PhotoRepository.DeleteComment(commentId, HttpContext.Current.User.Identity.Name);
         }
     });
 }
Exemplo n.º 6
0
 public void UpdateDescription(string description, string photoId)
 {
     ServiceSupport.AuthorizeAndExecute(() =>
     {
         if (HttpContext.Current.IsSuperAdminLoggedIn())
         {
             PhotoRepository.UpdateDescription(description, photoId);
         }
         else
         {
             PhotoRepository.UpdateDescription(description, photoId, HttpContext.Current.User.Identity.Name);
         }
     });
 }
Exemplo n.º 7
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);
             }
         }
     });
 }
Exemplo n.º 8
0
        public void CreateAlbum(Album album)
        {
            ServiceSupport.AuthorizeAndExecute(() =>
            {
                album.CreatedBy = HttpContext.Current.User.Identity.Name;
                var albumId     = AlbumRepository.SaveAlbum(album);

                // We just try to create folders. Sometimes this may fail
                // but we don't need to tell users anything wrong because
                // these folders will be created (if necessary) when users upload photos.
                try
                {
                    var storage = SharpBoxSupport.OpenDropBoxStorage();
                    storage.CreateFoldersForAlbum(albumId);
                    storage.Close();
                }
                catch (Exception ex)
                {
                    Logger.Error(ex.ToString());
                }
            });
        }
Exemplo n.º 9
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);
                    }
                }
            });
        }