Exemplo n.º 1
0
        public async Task <bool> RestoreByIdAsync(string id)
        {
            var video = await videoRepository.AllWithDeleted()
                        .Include(v => v.Comments)
                        .Include(v => v.Ratings)
                        .SingleOrDefaultAsync(v => v.Id == id);

            if (video == null)
            {
                return(false);
            }
            foreach (var rate in video.Ratings)
            {
                await rateService.RestoreByIdAsync(rate.Id);
            }
            foreach (var comment in video.Comments)
            {
                await commentSerivce.RestoreByIdAsync(comment.Id);
            }

            videoRepository.Undelete(video);
            var result = await videoRepository.SaveChangesAsync();

            return(result > 0);
        }
Exemplo n.º 2
0
        public async Task <bool> UnbanByIdAsync(string id)
        {
            var user = await userRepository.AllWithDeleted()
                       .Include(u => u.Uploads)
                       .Include(u => u.Ratings)
                       .Include(u => u.Comments)
                       .SingleOrDefaultAsync(u => u.Id == id);

            if (user == null)
            {
                return(false);
            }
            foreach (var rate in user.Ratings)
            {
                await rateService.RestoreByIdAsync(rate.Id);
            }
            foreach (var comment in user.Comments)
            {
                await commentSerivce.RestoreByIdAsync(comment.Id);
            }
            foreach (var video in user.Uploads)
            {
                await videoService.RestoreByIdAsync(video.Id);
            }
            userRepository.Undelete(user);


            await userRepository.SaveChangesAsync();


            return(true);
        }
        public async Task RestoreById_ShouldSetIsDeletedToFalse(string commentId, bool expected)
        {
            await commentService.DeleteByIdAsync("4");


            await commentService.RestoreByIdAsync(commentId);

            var actual = data.Any(c => c.IsDeleted);

            Assert.IsTrue(actual == expected);
        }
        public async Task <IActionResult> Restore([FromBody] CommentRestoreByIdBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetFirstError()));
            }
            var result = await commentSerivce.RestoreByIdAsync(model.Id);

            if (!result)
            {
                return(NotFound());
            }
            return(Ok());
        }