예제 #1
0
        public async Task <IActionResult> AddMovieToCollection([FromBody] AddMovieToCollectionRequest request)
        {
            MovieCollection collection = await this.movieCollections.GetById(request.collectionId);

            if (collection == null)
            {
                return(NotFound(new ErrorResponse {
                    Error = "Invalid collection id"
                }));
            }

            MovieCollectionItem movieCollectionItem = new MovieCollectionItem
            {
                MovieId           = request.MovieId,
                MovieCollectionId = collection.Id
            };

            if (await this.movieCollectionItems.Exists(request.MovieId, request.collectionId))
            {
                return(Conflict(new ErrorResponse {
                    Error = "Movie already added on collection"
                }));
            }

            MovieCollectionItem movieOnCollection = await this.movieCollectionItems.Add(movieCollectionItem);

            MovieCollectionItemResponse response = this.mapper.Map <MovieCollectionItemResponse>(movieOnCollection);

            return(CreatedAtAction("GetCollectionById", new { collectionId = response.MovieCollectionId }, response));
        }
        public async Task <bool> Delete(MovieCollectionItem movieCollectionItem)
        {
            string sql = @"
        DELETE FROM `MovieDB`.`MovieCollectionItems` WHERE `MovieId` = @MovieId AND `MovieCollectionId`= @MovieCollectionId;
      ";

            using (var conn = GetConnection())
            {
                await conn.ExecuteAsync(sql, movieCollectionItem);
            }

            return(true);
        }
        public async Task <MovieCollectionItem> Add(MovieCollectionItem movieCollectionItem)
        {
            string sql = @"
        INSERT INTO `MovieDB`.`MovieCollectionItems` (`MovieId`, `MovieCollectionId`) VALUES (@MovieId, @MovieCollectionId);
      ";

            using (var conn = GetConnection())
            {
                await conn.ExecuteAsync(sql, movieCollectionItem);
            }

            return(movieCollectionItem);
        }
 public Task <MovieCollectionItem> Update(MovieCollectionItem entity)
 {
     throw new System.NotImplementedException();
 }