コード例 #1
0
ファイル: DbContextTests.cs プロジェクト: mbobcik/VUT-FIT-BIT
        public void Delete_Photo()
        {
            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);

            photoRepo.Delete(photo.Id);

            Assert.Null(photoRepo.GetById(photo.Id));
            Assert.NotNull(albumRepo.GetById(album.Id));
        }
コード例 #2
0
        private static bool CleanupAlbum(CloudQueueMessage msg)
        {
            Trace.TraceInformation("CleanupAlbum called with {0}", msg.AsString);
            var parts = msg.AsString.Split('|');

            if (parts.Length != 2)
            {
                Trace.TraceError("Unexpected input to the album cleanup queue: {0}", msg.AsString);
                return(false);
            }

            // interpret the message
            var owner = parts[0];
            var album = parts[1];

            var repository = new PhotoRepository();

            var photos = repository.GetPhotosByAlbum(owner, album);

            // this will trigger another message to the queue for more scale!
            foreach (var photo in photos)
            {
                repository.Delete(photo);
            }

            return(true);
        }
コード例 #3
0
ファイル: PhotoController.cs プロジェクト: astromberg1/album
        public ActionResult Delete(int?id, int AlbumID)
        {
            string filePath = string.Empty;

            if (id != null && User.Identity.IsAuthenticated)
            {
                int photoID = (int)id;

                var photoToRemove = repo.ByID(photoID);
                //int AlbumID = (int)photoToRemove.AlbumID;

                if (photoToRemove != null)
                {
                    filePath = Request.MapPath(photoToRemove.Path);
                    FileInfo file = new FileInfo(filePath);

                    repo.Delete(photoToRemove.ID);


                    if (file.Exists)
                    {
                        file.Delete();
                    }
                }

                return(Json(Url.Action("ViewAlbum", "Album", new { id = AlbumID })));
            }
            //return new RedirectResult(Url.Action("ViewAlbum", "Album", new { id = AlbumID }));


            return(Json(Request.UrlReferrer.ToString()));
        }
コード例 #4
0
        public void DeleteByNullValue()
        {
            // Arrange
            PhotoRepository photoRepository = new PhotoRepository(dbContext);

            // Act
            // Assert
            Assert.ThrowsException <ArgumentNullException>(() => photoRepository.Delete(entityToDelete: null));
        }
コード例 #5
0
        public void DeleteByNullKey_Exception()
        {
            // Arrange
            PhotoRepository photoRepository = new PhotoRepository(dbContext);
            object          wrongId         = null;

            // Act
            // Assert
            Assert.ThrowsException <ArgumentNullException>(() => photoRepository.Delete(wrongId));
        }
コード例 #6
0
        public void DeleteByWrongKey_Exception()
        {
            // Arrange
            PhotoRepository photoRepository = new PhotoRepository(dbContext);
            Guid            wrongId         = default(Guid);

            // Act
            // Assert
            Assert.ThrowsException <InvalidOperationException>(() => photoRepository.Delete(wrongId));
        }
コード例 #7
0
        private void DeletePhoto(DeletePhotoMessage message)
        {
            var result = MessageBox.Show("Naozaj chcete vymazať túto fotku ?", "Vymazanie fotky", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.No)
            {
                return;
            }
            _photoRepository.Delete(message.PhotoId);
            var photo = Photos.FirstOrDefault(r => r.Id == message.PhotoId);

            if (photo != null)
            {
                Photos.Remove(photo);
            }
        }
コード例 #8
0
        public IHttpActionResult Delete(int photoId)
        {
            try
            {
                var request    = Context.AuthenticatedRequest;
                var repository = new PhotoRepository();

                var siteId = request.GetPostInt("siteId");
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(siteId, Utils.PluginId))
                {
                    return(Unauthorized());
                }

                repository.Delete(photoId);

                return(Ok(new {}));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #9
0
        public void DeleteByValue()
        {
            // Arrange
            PhotoRepository photoRepository = new PhotoRepository(dbContext);
            Photo           photoToDelete   = dbContext.Photos.First();

            // Act
            List <CommentLike> deletedCommentLikes = dbContext.CommentLike
                                                     .AsEnumerable().Where(cl => photoToDelete.Comments.Contains(cl.Comment)).ToList();

            photoRepository.Delete(photoToDelete);
            dbContext.SaveChanges();

            // Assert
            CollectionAssert.DoesNotContain(dbContext.Photos.ToArray(), photoToDelete);
            // Checks if all photo's likes are deleted.
            Assert.IsFalse(dbContext.PhotoLike.AsEnumerable().Any(pl => pl.Photo == null || pl.Photo.Id == photoToDelete.Id));
            // Checks if all photo's comments are deleted.
            Assert.IsFalse(dbContext.Comments.AsEnumerable().Any(c => c.Photo == null || c.Photo.Id == photoToDelete.Id));
            // Checks if all photo's comments' likes are deleted.
            CollectionAssert.IsNotSubsetOf(deletedCommentLikes, dbContext.CommentLike.ToList());
        }
コード例 #10
0
ファイル: DeletePhoto.cs プロジェクト: NhatTanVu/myalbum
        public async Task DeletePhoto()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <MyAlbumDbContext>()
                          .UseInMemoryDatabase(databaseName: "PhotoRepository_DeletePhoto_MyAlbumDatabase")
                          .Options;

            using (var context = new MyAlbumDbContext(options))
            {
                IEnumerable <Photo> seedPhotos      = SeedPhotos(context);
                UnitOfWork          unitOfWork      = new UnitOfWork(context);
                PhotoRepository     photoRepository = new PhotoRepository(context);
                int count = seedPhotos.Count();
                foreach (var photo in seedPhotos)
                {
                    // Act
                    photoRepository.Delete(photo);
                    await unitOfWork.CompleteAsync();

                    // Assert
                    Assert.Equal(--count, context.Photos.Count());
                }
            }
        }
コード例 #11
0
ファイル: Main.cs プロジェクト: siteserver/SS.Photo
        private static void Service_ContentDeleteCompleted(object sender, ContentEventArgs e)
        {
            var repository = new PhotoRepository();

            repository.Delete(e.SiteId, e.ChannelId, e.ContentId);
        }
コード例 #12
0
 public bool DeletePhoto(Photo photo)
 {
     return(_photoRepository.Delete(photo));
 }
コード例 #13
0
ファイル: Mapping.cs プロジェクト: chikanoff/AnimalShelter
        public static void DeletePhoto(PhotoData photo)
        {
            PhotoRepository photoRep = new PhotoRepository();

            photoRep.Delete(photo.Id);
        }
コード例 #14
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 });
 }
コード例 #15
0
        public ActionResult Delete(Guid id)
        {
            PhotoRepository.Delete(id);

            return(null);
        }