Beispiel #1
0
        private void AddMovieExecute()
        {
            if (!string.IsNullOrEmpty(Movie.Title))
            {
                Movie newMovie = new Movie
                {
                    Duration       = Movie.Duration,
                    Title          = Movie.Title,
                    Desctiprion    = Movie.Desctiprion,
                    Distributor_Id = _dALDistributor.AllDistributors().ElementAt(SelectedDistributor).Id,
                    Director_Id    = _dALDirector.AllDirectors().ElementAt(SelectedDirector).Id,
                    MetaScore      = 0,
                    Festivals      = new List <Festival>(),
                    Reviews        = new List <Review>(),
                    Actors         = new List <Actor>(),
                    Genres         = new List <Genre>(),
                    ShowsMovies    = new List <ShowsMovie>(),
                    Deleted        = false
                };

                _dALMovie.AddMovie(newMovie);
                var lastAddedMovie = _dALMovie.AllMovies().LastOrDefault();

                _movieActors.ForEach(a =>
                {
                    _dALActor.AddActsProcedure(a.Id, lastAddedMovie.Id);
                });

                _movieGenres.ForEach(g =>
                {
                    _dALGenre.AddBelongToGenreProcedure(g.Id, lastAddedMovie.Id);
                });

                _movieFestivals.ForEach(f => {
                    _dALFestival.AddMovieFestivalProcedure(f.Id, lastAddedMovie.Id);
                });

                _movieFestivalAward.ForEach(a => {
                    a.MovieFestival_Movie_Id = lastAddedMovie.Id;
                    _dALAward.AddMovieFestivalAward(a);
                });

                _showsMovie.ForEach(a =>
                {
                    a.Movie_Id = lastAddedMovie.Id;
                    _dALCinema.AddShowsMovie(a);
                });

                actor_window.Close();
            }
        }
        public IHttpActionResult PostMovie()
        {
            HttpRequestMessage request = this.Request;

            if (!request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            string root = System.Web.HttpContext.Current.Server.MapPath("~/Content/images/movies");

            // Get the uploaded image from the Files collection
            var httpPostedFile = HttpContext.Current.Request.Files["image"];
            var movie          = JsonConvert.DeserializeObject <Movie>(HttpContext.Current.Request.Form[0]);

            Validate(movie);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (httpPostedFile != null)
            {
                // Validate the uploaded image(optional)
                var extension = new FileInfo(httpPostedFile.FileName).Extension;
                var fileName  = Guid.NewGuid() + extension;
                // Get the complete file path
                var fileSavePath = Path.Combine(root, fileName);

                while (File.Exists(fileSavePath))
                {
                    fileName     = Guid.NewGuid() + extension;
                    fileSavePath = Path.Combine(root, fileName);
                }
                // Save the uploaded file to "UploadedFiles" folder
                httpPostedFile.SaveAs(fileSavePath);
                movie.Image = "http://localhost:50000/Content/images/movies/" + fileName;
            }

            _dALMovie.AddMovie(movie);

            return(CreatedAtRoute("DefaultApi", new { id = movie.Id }, movie));
        }