예제 #1
0
        public async Task <IActionResult> PutComment(int id, Comment comment)
        {
            if (id != comment.Id)
            {
                return(BadRequest());
            }

            _context.Entry(comment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        public async Task <MovieDTO> DeleteMovie(int id)
        {
            var movie = await _context.Movies
                        .Include(c => c.ActorMovies)
                        .Include(c => c.Comments)
                        .Include(c => c.Votes)
                        .Include(c => c.MovieGenres)
                        .FirstOrDefaultAsync(c => c.Id == id)
                        .ConfigureAwait(false);

            if (movie == null)
            {
                return(null);
            }

            _context.ActorMovies.RemoveRange(movie.ActorMovies);
            _context.Comments.RemoveRange(movie.Comments);
            _context.Votes.RemoveRange(movie.Votes);
            _context.MovieGenres.RemoveRange(movie.MovieGenres);

            _context.Movies.Remove(movie);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(new MovieDTO()
            {
                Id = movie.Id,
                Title = movie.Title,
                Description = movie.Description,
                ReleaseDate = movie.ReleaseDate,
                DirectorId = movie.DirectorId,
                Poster = movie.Poster
            });
        }
예제 #3
0
        public async Task <UserDeleteDTO> DeleteUser(string id)
        {
            var user = await _context.Users
                       .Include(c => c.Comments)
                       .Include(c => c.Votes)
                       .FirstOrDefaultAsync(c => c.Id == id).ConfigureAwait(false);

            if (user == null)
            {
                return(null);
            }

            _context.Comments.RemoveRange(user.Comments);
            _context.Votes.RemoveRange(user.Votes);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            await _userManager.DeleteAsync(user).ConfigureAwait(false);

            return(new UserDeleteDTO()
            {
                Id = user.Id,
                FirstName = user.FirstName,
                LastName = user.LastName,
                Username = user.UserName,
                Email = user.Email
            });
        }
예제 #4
0
        public async Task <GenreDTO> DeleteGenre(int id)
        {
            var genre = await _context.Genres.FirstOrDefaultAsync(a => a.Id == id).ConfigureAwait(false);

            if (genre == null)
            {
                return(null);
            }

            _context.Genres.Remove(genre);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(new GenreDTO()
            {
                Id = genre.Id,
                Category = genre.Category,
                Description = genre.Description
            });
        }
예제 #5
0
        public async Task <ActorDTO> DeleteActor(int id)
        {
            var actor = await _context.Actors.FirstOrDefaultAsync(a => a.Id == id).ConfigureAwait(false);

            if (actor == null)
            {
                return(null);
            }

            _context.Actors.Remove(actor);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(new ActorDTO()
            {
                Id = actor.Id,
                DateOfBirth = actor.DateOfBirth,
                gender = actor.gender
            });
        }
예제 #6
0
        public async Task <DirectorDTO> DeleteDirector(int id)
        {
            var director = await _context.Directors.FirstOrDefaultAsync(a => a.Id == id).ConfigureAwait(false);

            if (director == null)
            {
                return(null);
            }

            _context.Directors.Remove(director);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(new DirectorDTO()
            {
                Id = director.Id,
                Name = director.Name,
                gender = director.gender,
                DateOfBirth = director.DateOfBirth
            });
        }
예제 #7
0
        public async Task <CommentPutDTO> PostComment(CommentPutDTO commentPostDTO)
        {
            if (commentPostDTO == null)
            {
                throw new ArgumentNullException(nameof(commentPostDTO));
            }

            var commentResult = _context.Comments.Add(new Comment()
            {
                CommentText = commentPostDTO.CommentText,
                Date        = commentPostDTO.Date,
                MovieId     = commentPostDTO.MovieId,
                UserId      = commentPostDTO.UserId
            });

            await _context.SaveChangesAsync().ConfigureAwait(false);

            commentPostDTO.Id = commentResult.Entity.Id;

            return(commentPostDTO);
        }