public async Task DeleteById_ShouldSoftDeleteEntity(string commentId, bool expected)
        {
            await commentService.DeleteByIdAsync(commentId);

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

            Assert.IsTrue(actual == expected);
        }
Exemplo n.º 2
0
        public async Task <bool> DeleteByIdAsync(string id)
        {
            var video = await videoRepository.All()
                        .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.DeleteByIdAsync(rate.Id);
            }
            foreach (var comment in video.Comments)
            {
                await commentSerivce.DeleteByIdAsync(comment.Id);
            }

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

            return(result > 0);
        }
Exemplo n.º 3
0
        public async Task <bool> BanByUsernameAsync(string username)
        {
            var user = await userRepository.All()
                       .Include(u => u.Uploads)
                       .Include(u => u.Ratings)
                       .Include(u => u.Comments)
                       .SingleOrDefaultAsync(u => u.UserName == username);

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

            await userRepository.SaveChangesAsync();


            return(true);
        }
        public async Task <IActionResult> Delete(string id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetFirstError()));
            }
            var result = await commentSerivce.DeleteByIdAsync(id);

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