示例#1
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));
        }
示例#2
0
        public async Task <ActionResult> PostUser([FromBody] User user)
        {
            _context.Users.Add(user);

            ChangeLog.AddCreatedLog(_context, "Users", user);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUser", new { id = user.Id }, user));
        }
示例#3
0
        public async Task <ActionResult <ProductBookSubject> > PostProductBookSubject(ProductBookSubject productBookSubject)
        {
            _context.ProductBookSubjects.Add(productBookSubject);

            ChangeLog.AddCreatedLog(_context, "BookSubjects", productBookSubject);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProductBookSubject", new { id = productBookSubject.Id }, productBookSubject));
        }
示例#4
0
        public async Task <ActionResult <ProductSongGenre> > PostProductSongGenre(ProductSongGenre productSongGenre)
        {
            _context.ProductSongGenres.Add(productSongGenre);

            ChangeLog.AddCreatedLog(_context, "SongGenres", productSongGenre);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProductSongGenre", new { id = productSongGenre.Id }, productSongGenre));
        }
示例#5
0
        public async Task <ActionResult <UserRole> > PostUserRole(UserRole userRole)
        {
            _context.UserRoles.Add(userRole);

            ChangeLog.AddCreatedLog(_context, "UserRoles", userRole);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUserRole", new { id = userRole.Id }, userRole));
        }
示例#6
0
        public async Task <ActionResult <ProductMovieActor> > PostProductMovieActor(ProductMovieActor productMovieActor)
        {
            _context.ProductMovieActors.Add(productMovieActor);

            ChangeLog.AddCreatedLog(_context, "MovieActors", productMovieActor);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProductMovieActor", new { id = productMovieActor.Id }, productMovieActor));
        }
示例#7
0
        public async Task <ActionResult <SystemConfiguration> > PostSystemConfiguration(SystemConfiguration systemConfiguration)
        {
            _context.SystemConfigurations.Add(systemConfiguration);

            ChangeLog.AddCreatedLog(_context, "SystemConfigurations", systemConfiguration);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSystemConfiguration", new { id = systemConfiguration.Id }, systemConfiguration));
        }
示例#8
0
        public async Task <IActionResult> PutProductBook(string id, ProductBookDAO productBookDao)
        {
            var product = new Product();

            product.Title           = productBookDao.Title;
            product.Price           = productBookDao.Price;
            product.ReleaseYear     = productBookDao.ReleaseYear;
            product.Language        = productBookDao.Language;
            product.Type            = ProductType.Book;
            product.FilePath        = productBookDao.FilePath;
            product.PreviewFilePath = productBookDao.PreviewFilePath;

            var productBook = new ProductBook();
            var bookSubject = new ProductBookSubject();

            productBook.Subject   = bookSubject;
            productBook.Author    = productBookDao.Author;
            productBook.Publisher = productBookDao.Publisher;
            productBook.Product   = product;
            productBook.Code      = productBookDao.Code;

            ChangeLog.AddCreatedLog(_context, "Books", productBook);

            if (id != productBookDao.Code)
            {
                return(BadRequest());
            }


            if (id != productBook.Code)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#9
0
        public async Task <ActionResult <ProductSong> > PostProductSong(ProductSongDAO productSongDao)
        {
            var product = new Product();

            product.Title           = productSongDao.Title;
            product.Price           = productSongDao.Price;
            product.ReleaseYear     = productSongDao.ReleaseYear;
            product.Language        = productSongDao.Language;
            product.Type            = ProductType.Song;
            product.FilePath        = productSongDao.FilePath;
            product.PreviewFilePath = productSongDao.PreviewFilePath;

            _context.Products.Add(product);

            var song = new ProductSong();

            song.Album   = productSongDao.Album;
            song.Country = productSongDao.Country;

            var songGenere = _context.ProductSongGenres.Single(songGenere => songGenere.Id == productSongDao.GenreId);

            song.Genre = songGenere;

            song.Artist  = productSongDao.Artist;
            song.Label   = productSongDao.Label;
            song.Product = product;

            var songsConsecutive = _context.TableConsecutives.Single(tableConsecutive => tableConsecutive.Table == "Musica");

            song.Code = songsConsecutive.GetCurrentCode();
            song.InterpretationType = (SongInterpretationType)productSongDao.InterpretationType;

            _context.ProductSongs.Add(song);

            ChangeLog.AddCreatedLog(_context, "Songs", song);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ProductSongExists(song.Code))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetProductSong", new { id = song.Code }, song));
        }
示例#10
0
        public async Task <ActionResult <TableConsecutive> > PostTableConsecutive(TableConsecutive tableConsecutive)
        {
            if (tableConsecutive.Prefix != "")
            {
                tableConsecutive.UsesPrefix = true;
            }

            if (tableConsecutive.RangeMin != null || tableConsecutive.RangeMax != null)
            {
                tableConsecutive.UsesRange = true;
            }

            _context.TableConsecutives.Add(tableConsecutive);

            ChangeLog.AddCreatedLog(_context, "TableConsecutives", tableConsecutive);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTableConsecutive", new { id = tableConsecutive.Id }, tableConsecutive));
        }
示例#11
0
        public async Task <ActionResult <ProductBook> > PostProductBook(ProductBookDAO productBookDao)
        {
            var product = new Product();

            product.Title           = productBookDao.Title;
            product.Price           = productBookDao.Price;
            product.ReleaseYear     = productBookDao.ReleaseYear;
            product.Language        = productBookDao.Language;
            product.Type            = ProductType.Book;
            product.FilePath        = productBookDao.FilePath;
            product.PreviewFilePath = productBookDao.PreviewFilePath;

            _context.Products.Add(product);

            var book        = new ProductBook();
            var bookSubject = new ProductBookSubject();

            book.Author    = productBookDao.Author;
            book.Publisher = productBookDao.Publisher;

            var booksConsecutive = _context.TableConsecutives.Single(tableConsecutive => tableConsecutive.Table == "Libros");

            book.Code    = booksConsecutive.GetCurrentCode();
            book.Product = product;

            try
            {
                bookSubject = _context.ProductBookSubjects.Single(bookSubject => bookSubject.Id == productBookDao.SubjectId);
            }
            catch
            {
                bookSubject = null;
            }

            book.Subject = bookSubject;

            _context.ProductBooks.Add(book);

            ChangeLog.AddCreatedLog(_context, "Books", book);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ProductExists(product.Id))
                {
                    return(Conflict());
                }
                else if (ProductBookExists(book.Code))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetProductBook", new { id = book.Code }, book));
        }