示例#1
0
        public IHttpActionResult PutMovie(int id)
        {
            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)
            {
                var extension    = new FileInfo(httpPostedFile.FileName).Extension;
                var fileName     = Guid.NewGuid() + extension;
                var fileSavePath = Path.Combine(root, fileName);

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

            if (id != movie.Id)
            {
                return(BadRequest());
            }

            _dALMovie.UpdateMovie(movie);

            return(StatusCode(HttpStatusCode.NoContent));
        }
        private void UpdateMovieExecute()
        {
            try
            {
                _movieActors.ForEach(a =>
                {
                    _dALActor.AddActsProcedure(a.Id, _movie.Id);
                });

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

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

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

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

                _dALHelper.UpdateMovie(_movie);

                window.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }