Exemplo n.º 1
0
        public void DeleteAlbum_With_Photos()
        {
            //set up

            Photo photo = new Photo
            {
                DateTime   = DateTime.Now,
                Name       = "testPhoto",
                FileFormat = FileFormat.gif,
                Path       = "My/path/to/file",
                Id         = AddNewGuid()
            };
            AlbumDetailModel album = new AlbumDetailModel()
            {
                DateTime    = DateTime.Now,
                Description = "Description",
                Id          = TestGuidList.ElementAt(0),
                Name        = "TmpAlbum1",
                Photos      = new List <PhotoListModel> {
                    mapper.EntityToListModel(photo)
                }
            };

            photo.Album = mapper.DetailModelToEntity(album);
            albumRepo.Insert(album);
            photoRepo.Insert(mapper.EntityToDetailModel(photo), album.Id);

            //unit test
            albumRepo.Delete(TestGuidList.ElementAt(0));

            //Assert
            Assert.Null(albumRepo.GetById(TestGuidList.ElementAt(0)));
            Assert.Null(photoRepo.GetById(TestGuidList.ElementAt(1)));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Download(string imageId, bool thumb = false)
        {
            int id;

            if (string.IsNullOrEmpty(imageId) || !Int32.TryParse(imageId, out id))
            {
                return(new HttpUnauthorizedResult());
            }

            IReadWriteRepository <ServiceData.Models.Photo>         _photoRepository = new PhotoRepository();
            IReadWriteRepository <ServiceData.Models.UserCondition> _condRepository  = new UserConditionsRepository();

            ServiceData.Models.Photo found = _photoRepository.GetById(id);
            if (found == null)
            {
                return(new HttpNotFoundResult());
            }

            ServiceData.Models.UserCondition foundCond = _condRepository.GetById(found.UserCondition.Id);
            if (!IsSharedOrOwned(foundCond))
            {
                return(new HttpUnauthorizedResult());
            }

            string target = (thumb) ? found.ThumbUrl : found.Url;

            CloudBlobContainer container = await UploadController.GetBlobContainer();

            Stream    blobStream = new MemoryStream();
            CloudBlob photoBlob  = container.GetBlobReference(target.Replace(ConfidentialData.BlobStorageUrl, ""));

            KeyVaultKeyResolver cloudResolver = new KeyVaultKeyResolver(ServerUtils.GetToken);
            IKey rsa = await cloudResolver.ResolveKeyAsync(ConfidentialData.KeyLocation, CancellationToken.None);

            BlobEncryptionPolicy policy  = new BlobEncryptionPolicy(null, cloudResolver);
            BlobRequestOptions   options = new BlobRequestOptions()
            {
                EncryptionPolicy = policy
            };

            await photoBlob.DownloadToStreamAsync(blobStream, null, options, null);

            blobStream.Position = 0;

            return(File(blobStream, "image/jpeg"));
        }
Exemplo n.º 3
0
        public ActionResult Describe(int id)
        {
            UserModel authUser = (User.Identity.IsAuthenticated ?
                new UserRepository().GetByUsername( User.Identity.Name ) : null);

            // check if photo with given id exists
            PhotoRepository photos = new PhotoRepository();
            PhotoModel photo = photos.GetById( id, withAlbum: true );
            if ( photo == null )
                throw new Exception( "photo not found" );

            // check if the caller can access the album containing the photo
            AlbumRepository albums = new AlbumRepository();
            AlbumModel album = albums.GetById( photo.Album.Id, withUser: true, withTrustedUsers: true );
            if ( !albums.IsUserAuthorizedToViewAlbum( album, authUser, false ) )
                throw new Exception( "user not authorized to view this photo/album" );

            // send back the photo information
            return Json( new
            {
                ok = true,
                data = new
                {
                    id = photo.Id,
                    album = string.Format( "{0}/api/albums/{1}", Helpers.BaseURL(), album.Id ),
                    date = new
                    {
                        day = photo.Date.Day,
                        month = photo.Date.Month,
                        year = photo.Date.Year
                    },
                    description = photo.Description,
                    image = Helpers.BaseURL() + photo.Path,
                    thumbnail = Helpers.BaseURL() + photo.Path.Substring(0, photo.Path.LastIndexOf(".jpg")) + "_mini.jpg",
                    latitude = photo.LocationLatitude,
                    longitude = photo.LocationLongitude
                }
            }, JsonRequestBehavior.AllowGet );
        }
Exemplo n.º 4
0
 public ActionResult DeletePhoto(long photoId)
 {
     try
     {
         var photoRepo = new PhotoRepository();
         var photo = photoRepo.GetById(photoId);
         if (null != photo)
         {
             photoRepo.Remove(photo);
         }
     }
     catch (Exception e)
     {
         return Json(new { Status = "Failed", Description = e.Message });
     }
     return Json(new { Status = "OK", Description = "" });
 }
Exemplo n.º 5
0
 private void ShowDetailPhotoMessageReceived(ShowDetailPhotoMessage message)
 {
     Detail = _photoRepository.GetById(message.Id);
 }
Exemplo n.º 6
0
 public ActionResult DeletePhotos(int albumId, int[] selectedObjects)
 {
     //TODO access control
     PhotoRepository photos = new PhotoRepository();
     if (selectedObjects != null)
     {
         foreach (int id in selectedObjects)
         {
             PhotoModel photo = photos.GetById(id);
             if (photo.Album.Id == albumId)
                 photos.Delete(photo);
         }
     }
     return RedirectToAction("ManageAlbum", new { id = albumId });
 }