コード例 #1
0
 public virtual ActionResult AddToImportTree(int id, int treeId, HttpPostedFileBase imageData)
 {
     using (var uow = UnitOfWork.Begin())
     {
         var trip = Repositories.Imports.FindById(id);
         var tree = trip.FindTreeById(treeId);
         using (imageData.InputStream)
         {
             var photo = TemporaryPhoto.Create(imageData.InputStream);
             tree.AddPhoto(photo);
             this.ValidateMappedModel <TreeBase, PhotoGalleryModel>(tree);
             if (ModelState.IsValid)
             {
                 UnitOfWork.Flush();
                 if (!Repositories.Photos.ListAllReferencesByPhotoId(photo.StaticId).IsAuthorizedToAdd(User))
                 {
                     return(new UnauthorizedResult());
                 }
                 uow.Persist();
             }
             else
             {
                 tree.RemovePhoto(photo);
             }
             var photoGallery = Mapper.Map <TreeBase, ImportTreePhotoGalleryModel>(tree);
             return(PhotoAdded(photoGallery));
         }
     }
 }
コード例 #2
0
        public void Stores()
        {
            Photo photo = TemporaryPhoto.Create("Medium.jpg".GetPhoto());

            using (Stream sourceData = photo.GetData())
                using (Stream destinationData = PhotoStoreProvider.Current.GetWriteStream(photo))
                {
                    sourceData.CopyTo(destinationData);
                }
        }
コード例 #3
0
        public void PersistsTreeWithPhotos()
        {
            Trip trip = Trip.Create();

            trip.MeasurerContactInfo = "measurer contact info";
            trip.Name = "name";
            trip.Measurers.Add(Name.Create("tree measurer 1 first name", "tree measurer 1 last name"));

            Site site1 = trip.AddSite();

            site1.Name          = "site 1 name";
            site1.County        = "site 1 county";
            site1.OwnershipType = "site 1 ownership type";
            site1.State         = Repositories.Locations.FindStateByCountryAndStateCode("US", "OH");
            Site site2 = trip.AddSite();

            site2.Name          = "site 2 name";
            site2.County        = "site 2 county";
            site2.OwnershipType = "site 2 ownership type";
            site2.State         = Repositories.Locations.FindStateByCountryAndStateCode("US", "OH");

            TreeBase tree1 = site2.AddSingleTrunkTree();

            tree1.CommonName     = "tree measurement 1 common name";
            tree1.ScientificName = "tree measurement 1 scientific name";

            MultiTrunkTree tree2 = site2.AddMultiTrunkTree();

            tree2.CommonName     = "tree measurement 2 common name";
            tree2.ScientificName = "tree measurement 2 scientific name";

            tree2.AddPhoto(TemporaryPhoto.Create("Square.jpg".GetPhoto()));
            tree2.AddPhoto(TemporaryPhoto.Create("Thumbnail.jpg".GetPhoto()));

            using (var uow = UnitOfWork.Begin())
            {
                Repositories.Imports.Save(trip);
                uow.Persist();
            }

            UnitOfWork.Dispose();

            using (var uow = UnitOfWork.Begin())
            {
                Trip found = Repositories.Imports.FindById(trip.Id);
                Assert.IsNotNull(found);
                Assert.AreEqual(2, found.Sites.Count);
                Assert.AreEqual(2, found.Sites[1].Trees.Count);
                Assert.AreEqual(2, found.Sites[1].Trees[1].Photos.Count);
                Assert.IsTrue("Square.jpg".GetPhoto().CompareByContent(found.Sites[1].Trees[1].Photos[0].Get()));
                Assert.IsTrue("Thumbnail.jpg".GetPhoto().CompareByContent(found.Sites[1].Trees[1].Photos[1].Get()));
                Repositories.Imports.Remove(found);
                uow.Persist();
            }
        }
コード例 #4
0
        public void SavesAndFindsPhoto()
        {
            IPhoto photo = new PublicPhotoReference(TemporaryPhoto.Create("Original.jpg".GetPhoto()));

            using (var uow = UnitOfWork.Begin())
            {
                Repositories.Photos.Save(photo);
                uow.Persist();
            }
            UnitOfWork.Dispose();
            using (var uow = UnitOfWork.Begin())
            {
                IPhoto found = Repositories.Photos.FindById(photo.StaticId);
                Assert.IsNotNull(found);
                Assert.IsTrue("Original.jpg".GetPhoto().CompareByContent(found.Get()));
                Repositories.Photos.Remove(found);
                uow.Persist();
            }
        }