コード例 #1
0
        public async Task <IActionResult> PutProductMovie(string id, ProductMovie productMovie)
        {
            if (id != productMovie.Code)
            {
                return(BadRequest());
            }

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

            ChangeLog.AddUpdatedLog(_context, "Movies", productMovie);

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

            return(NoContent());
        }
コード例 #2
0
        public async Task <ActionResult <ProductMovie> > PostProductMovie(ProductMovieDAO productMovieDao)
        {
            var product = new Product();

            product.Title           = productMovieDao.Title;
            product.Price           = productMovieDao.Price;
            product.ReleaseYear     = productMovieDao.ReleaseYear;
            product.Language        = productMovieDao.Language;
            product.Type            = ProductType.Movie;
            product.FilePath        = productMovieDao.FilePath;
            product.PreviewFilePath = productMovieDao.PreviewFilePath;

            _context.Products.Add(product);

            var movie             = new ProductMovie();
            var moviesConsecutive = _context.TableConsecutives.Single(tableConsecutive => tableConsecutive.Table == "Peliculas");

            movie.Code    = moviesConsecutive.GetCurrentCode(); //Consecutivo;
            movie.Product = product;

            var movieGenre = _context.ProductMovieGenres.Single(movieGenre => movieGenre.Id == productMovieDao.GenreId);

            List <ProductMovieActor> movieActor = new List <ProductMovieActor>();

            if (productMovieDao.ActorIds != null)
            {
                for (int i = 0; i < productMovieDao.ActorIds.Count; i++)
                {
                    var actor = new ProductMovieActor();
                    actor = _context.ProductMovieActors.Single(actor => actor.Id == productMovieDao.ActorIds[i]);
                    movieActor.Add(actor);
                }
            }
            movie.Genre = movieGenre;

            movie.Actors = movieActor;

            _context.ProductMovies.Add(movie);

            ChangeLog.AddCreatedLog(_context, "Movies", movie);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ProductMovieExists(movie.Code))
                {
                    //return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetProductMovie", new { id = movie.Code }, movie));
        }