public IHttpActionResult CreateActor(ActorDTO actorDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Existen Campos  invalidos"));
            }



            var movies = actorDTO.Movies.Select(a => a.ID);

            var Movies = _contex.Movies.Where(a => movies.Contains(a.ID)).ToList();


            var actor = Mapper.Map <ActorDTO, Actor>(actorDTO);

            actor.Movies = Movies;

            try
            {
                _contex.Actors.Add(actor);

                _contex.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }


            actorDTO.ID = actor.ID;

            return(Created(new Uri(Request.RequestUri + "" + actor.ID), actorDTO));
        }
示例#2
0
        public void GenerateTest(string question, string answer)
        {
            Question test = new Question
            {
                Quest  = question,
                Answer = answer
            };

            db.Questions.Add(test);
            db.SaveChanges();
        }
示例#3
0
        public IHttpActionResult CreateMovieGenres(MovieGenreDTO movieGenreDTO)
        {
            if (!ModelState.IsValid)
            {
                BadRequest();
            }

            var movieGenre = Mapper.Map <MovieGenreDTO, MovieGenre>(movieGenreDTO);

            _contex.MovieGenres.Add(movieGenre);

            _contex.SaveChanges();

            movieGenreDTO.ID = movieGenre.ID;

            return(Created(new Uri(Request.RequestUri + "" + movieGenre.ID), movieGenreDTO));
        }
        public IActionResult Registration(Person person)
        {
            _db.Person.Add(person);
            int flag = _db.SaveChanges();

            ViewData["nid"]     = person.Id.ToString().PadLeft(8, '0');;
            ViewData["Message"] = flag == 1 ? "Data inserted successfully" : "Failed";

            return(View());
        }
        public IHttpActionResult CreateMovie(MovieDTO MovieDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Valores Invalidos"));
            }


            var movieWithTitleRepeted = _contex.Movies.Where(m => m.Title == MovieDTO.Title).ToList();

            if (movieWithTitleRepeted.Count != 0)
            {
                return(BadRequest("Una pelicula con este titulo ya existe, No pueden existir dos peliculas con el mismo titulo"));
            }

            var movieActorsDTOId = MovieDTO.actors.GroupBy(a => a.ID).Where(a => a.Count() > 1).ToList();

            if (movieActorsDTOId.Count != 0)
            {
                return(BadRequest("Ha intentado ingresar un actor ya existente, El mismo Actor no puede existir mas de una vez en la misma pelicula"));
            }



            var Movies = _contex.Movies.ToList();


            var MovieGenre = _contex.MovieGenres.SingleOrDefault(m => m.ID == MovieDTO.MovieGenreID);


            if (MovieGenre == null)
            {
                return(BadRequest());
            }


            var Movie = Mapper.Map <MovieDTO, Movie>(MovieDTO);

            var actors = MovieDTO.actors.Select(a => a.ID);

            var Actors = _contex.Actors.Where(a => actors.Contains(a.ID)).ToList();

            Movie.Genre  = MovieGenre;
            Movie.Actors = Actors;


            _contex.Movies.Add(Movie);



            _contex.SaveChanges();



            var movieDto = Mapper.Map <Movie, MovieDTO>(Movie);



            movieDto.ID = Movie.ID;

            return(Created(new Uri(Request.RequestUri + "" + Movie.ID), movieDto));
        }