Beispiel #1
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> DeleteById(string id)
        {
            bool result = await _videoService.DeleteByIdAsync(id);

            if (!result)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Beispiel #3
0
        public async Task <IActionResult> Delete(string id)
        {
            if (!ModelState.IsValid || id == null)
            {
                return(BadRequest(ModelState.GetFirstError()));
            }
            var result = await videoService.DeleteByIdAsync(id);

            if (!result)
            {
                return(NotFound());
            }
            return(Ok());
        }
        public async Task DeleteById_ShouldSoftDeleteVideoAndAllItsCommentsAndRatings()
        {
            var result = await videoService.DeleteByIdAsync(null);

            Assert.IsFalse(result);

            await videoService.DeleteByIdAsync("10");

            var video = videoData.SingleOrDefault(v => v.Id == "10");

            Assert.IsTrue(video.IsDeleted);
            foreach (var comment in video.Comments)
            {
                var isDisabled = commentData.SingleOrDefault(c => c.Id == comment.Id).IsDeleted;
                Assert.IsTrue(isDisabled);
            }
            foreach (var rate in video.Ratings)
            {
                var isDisabled = rateData.SingleOrDefault(r => r.Id == rate.Id).IsDeleted;
                Assert.IsTrue(isDisabled);
            }
            Assert.IsTrue(video.IsDeleted);
        }
Beispiel #5
0
        public async Task <IHttpActionResult> Delete(string id)
        {
            if (string.IsNullOrEmpty(id) || !Guid.TryParse(id, out var _))
            {
                return(BadRequest());
            }
            try
            {
                await _videoService.DeleteByIdAsync(id);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }