public async Task <ActionResult> PostQuote(int actorId, int movieId, string quote)
        {
            if (actorId <= 0 || movieId <= 0 || string.IsNullOrEmpty(quote) || string.IsNullOrWhiteSpace(quote))
            {
                return(BadRequest());
            }
            var quotes = _context.Quotes;

            quotes.Add(new Models.Quote {
                ActorId = actorId,
                MovieId = movieId,
                Content = quote
            });
            await _context.SaveChangesAsync();

            var addedQuote = _context.Quotes.FirstOrDefaultAsync(q => q.Content == quote).Result;

            return(CreatedAtAction(nameof(GetQuote), new { id = addedQuote.Id }, addedQuote));
        }
Beispiel #2
0
        public async Task <ActionResult> PostDialogue(int movieId, string dialogue)
        {
            if (movieId <= 0 || string.IsNullOrEmpty(dialogue) || string.IsNullOrWhiteSpace(dialogue))
            {
                return(BadRequest());
            }
            var dialogues = _context.Dialogues;

            dialogues.Add(new Models.Dialogue
            {
                Content = dialogue,
                MovieId = movieId
            });
            await _context.SaveChangesAsync();

            var addedDialogue = _context.Dialogues.FirstOrDefaultAsync(d => d.Content == dialogue).Result;

            return(CreatedAtAction(nameof(GetDialogue), new { id = addedDialogue.Id }, addedDialogue));
        }
        public async Task <ActionResult> PostMovie(string title, int year, string director)
        {
            if (year <= 0 || string.IsNullOrEmpty(title) || string.IsNullOrWhiteSpace(title) ||
                string.IsNullOrEmpty(director) || string.IsNullOrWhiteSpace(director))
            {
                return(BadRequest());
            }
            var movies = _context.Movies;

            movies.Add(new Models.Movie
            {
                Director = director,
                Title    = title,
                Year     = year
            });
            await _context.SaveChangesAsync();

            var addedMovie = _context.Movies.FirstOrDefaultAsync(m => m.Title == title).Result;

            return(CreatedAtAction(nameof(GetMovie), new { id = addedMovie.Id }, addedMovie));
        }
        public async Task <ActionResult> PostActor(string name, string surname, DateTime birth, string birthPlace)
        {
            if (!IsValidStringInput(name) || !IsValidStringInput(surname) ||
                !IsValidStringInput(birthPlace) || birth == null)
            {
                return(BadRequest());
            }
            var actors = _context.Actors;

            actors.Add(new Models.Actor
            {
                Name       = name,
                Surname    = surname,
                Birth      = birth,
                BirthPlace = birthPlace
            });
            await _context.SaveChangesAsync();

            var addedActor = _context.Actors.FirstOrDefaultAsync(a => a.Name == name && a.Surname == surname).Result;

            return(CreatedAtAction(nameof(GetActor), new { id = addedActor.Id }, addedActor));
        }