public void Save(TadmapImage image)
      {
         bool isNew = false;

         TadmapDb db = new TadmapDb();
         UserImage dbImage = db.UserImages.SingleOrDefault(i => i.Id == image.Id);

         if (dbImage == null)
         {
            dbImage = new UserImage();

            // can't change date added, id or owner
            dbImage.DateAdded = DateTime.Now;
            dbImage.UserId = image.UserId;
            dbImage.Id = image.Id;

            isNew = true;
         }
         else
         {
            isNew = false;
         }

         dbImage.Title = image.Title;
         dbImage.Description = image.Description;
         dbImage.Key = image.Key;
         dbImage.OffensiveCount = image.IsOffensive ? (byte)1 : (byte)0;
         dbImage.Privacy = image.IsPublic ? (byte)1 : (byte)0;

         if (isNew)
            db.UserImages.InsertOnSubmit(dbImage);

         db.SubmitChanges();
      }
Beispiel #2
0
      public void ConfirmUpload(IPrincipal principal, string name, string key)
      {
         TadmapImage image = new TadmapImage();
         image.Title = Path.GetFileNameWithoutExtension(name);
         image.Description = "";
         image.Key = key;
         image.ImageSet = new ImageSet1(image.Key);
         image.UserId = (principal.Identity as TadmapIdentity).Id;
         image.ImageSetVersion = 0;

         _imageRepository.Save(image);

         _messageQueue.Add(key);
      }
Beispiel #3
0
      public void Collector_Should_Not_Be_Able_To_Mark_Image_As_Offensive()
      {
         TadmapImage image = new TadmapImage(new TestImageRepository(), new TestBinaryRepository())
         {
            Id = _imageId,
            Title = "title",
            Description = "description",
            Key = "key",
            IsPublic = false,
            IsOffensive = false,
            UserId = Guid.NewGuid()
         };

         Assert.IsFalse(image.CanUserMarkAsOffensive(Principals.Collector));
      }
Beispiel #4
0
      public ActionResult Upload(string title, string description, IPrincipal principal, IUploadedFile file)
      {
         if (file.ContentLength > 0)
         {
            TadmapImage image = new TadmapImage();
            image.Title = title ?? Path.GetFileNameWithoutExtension(file.FileName);
            image.Description = description ?? "";
            image.Key = Guid.NewGuid() + Path.GetExtension(file.FileName);
            image.ImageSet = new ImageSet1(image.Key);
            image.UserId = (principal.Identity as TadmapIdentity).Id;

            _imageRepository.Save(image);
         }

         return RedirectToAction("Index", "Home");
      }
      public void Can_Add_New_Image()
      {
         using (TransactionScope transaction = new TransactionScope())
         {
            IImageRepository repository = new SqlImageRepository();

            TadmapImage newImage = new TadmapImage(repository, null)
            {
               Id = Guid.NewGuid(),
               Title = "",
               Description = "",
               Key = "",
               IsPublic = true,
               IsOffensive = false,
               UserId = new Guid("d23a1f2a-0db5-4efe-b084-b5529e9a2756")
            };

            repository.Save(newImage);
         }
      }
      public void Can_Save_Image()
      {
         IImageRepository repository = CreateImageRepository();

         var image = new TadmapImage()
         {
            Key = "key",
            TileSize = 10,
            ZoomLevel = 20
         };

         repository.Save(image);

         var savedImage = repository.GetAllImages().Where(i => i.Key == image.Key).Single();

         Assert.AreEqual(image.Key, savedImage.Key);
         Assert.AreEqual(image.TileSize, savedImage.TileSize);
         Assert.AreEqual(image.ZoomLevel, savedImage.ZoomLevel);
         Assert.AreEqual(image.HasIcon, savedImage.HasIcon);
      }
      public void Save(TadmapImage image)
      {
         bool isNew = false;

         TadmapDb db = new TadmapDb(ConnectionString);
         Image dbImage = db.Images.SingleOrDefault(i => i.Id == image.Id);

         if (dbImage == null)
         {
            dbImage = new Image();

            // can't change date added, id or owner
            dbImage.DateAdded = DateTime.Now;
            dbImage.UserId = image.UserId;

            isNew = true;
         }
         else
         {
            isNew = false;
         }

         dbImage.Title = image.Title;
         dbImage.Description = image.Description;
         dbImage.Key = image.Key;
         dbImage.OffensiveCount = image.IsOffensive ? (byte)1 : (byte)0;
         dbImage.Privacy = image.IsPublic ? (byte)1 : (byte)0;
         dbImage.TileSize = image.TileSize;
         dbImage.ZoomLevels = image.ZoomLevel > 0 ? new int?(image.ZoomLevel) : null;
         dbImage.ThumbnailAvailable = image.HasIcon;

         if (isNew)
            db.Images.InsertOnSubmit(dbImage);

         db.SubmitChanges();
      }
 public void Save(TadmapImage image)
 {
    
 }
Beispiel #9
0
      public void Has_ImageSet_Accessor()
      {
         TadmapImage image = new TadmapImage(new TestImageRepository(), new TestBinaryRepository());

         Assert.IsNull(image.ImageSet);
      }
Beispiel #10
0
      public void Contains_OwnerName()
      {
         TadmapImage image = new TadmapImage(new TestImageRepository(), new TestBinaryRepository()) { OwnerName = "Owner" };

         Assert.AreEqual("Owner", image.OwnerName);
      }
Beispiel #11
0
      public void HasThumbUrl()
      {
         TadmapImage image = new TadmapImage(new TestImageRepository(), new TestBinaryRepository())
         {
            Key = "theKey",
            ImageSet = new ImageSet1("theKey")
         };


         Assert.That(image.SquareUrl, Is.EqualTo(new Uri("http://Square_theKey.url")));

      }
      public void GetAll_Count_Is_4_After_Saving_New_Image()
      {
         using (TransactionScope transaction = new TransactionScope())
         {
            IImageRepository repository = new SqlImageRepository();

            TadmapImage newImage = new TadmapImage(repository, null)
            {
               Id = Guid.NewGuid(),
               Title = "",
               Description = "",
               Key = "",
               IsPublic = true,
               IsOffensive = false,
               UserId = new Guid("d23a1f2a-0db5-4efe-b084-b5529e9a2756")
            };

            repository.Save(newImage);

            Assert.AreEqual(4, repository.GetAllImages(new TestBinaryRepository()).Count());
         }
      }
      public void Contains_Save_Method()
      {
         IImageRepository repository = new TestImageRepository();

         TadmapImage image = new TadmapImage(new TestImageRepository(), new TestBinaryRepository());

         repository.Save(image);
      }
 public void Save(TadmapImage image)
 {
    _images.Add(image);
 }