public PhotoComment CreateComment(PhotoComment comment) { PhotoComment result = null; ServiceSupport.AuthorizeAndExecute(() => { result = PhotoRepository.CreateComment(comment); }); return(result); }
public string RequestPhotoUploadTicket(string requestToken) { string result = null; // Only logged-in user can get the ticket ServiceSupport.AuthorizeAndExecute(() => { result = PhotoUploadTicketPool.GenerateTicket(requestToken); }); return(result); }
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); }
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); }
public void DeleteComment(string commentId) { ServiceSupport.AuthorizeAndExecute(() => { if (HttpContext.Current.IsSuperAdminLoggedIn()) { PhotoRepository.DeleteComment(commentId); } else { PhotoRepository.DeleteComment(commentId, HttpContext.Current.User.Identity.Name); } }); }
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); } }); }
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); } } }); }
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()); } }); }
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); } } }); }