Пример #1
0
        public ActionResult AddPhotoToFilmPost(int id)
        {
            var movie = _movieDataProvider.GetMovieById(id, null);

            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];
                if (file != null && file.ContentLength > 0)
                {
                    var fileName = FileHelpers.GenerateFilename(movie.Title, file.FileName);
                    var photoUrl = Path.Combine(
                        Server.MapPath(movie.Folder), fileName);
                    file.SaveAs(photoUrl);
                    movie.PhotoUrl = photoUrl;
                }
                for (var i = 0; i < Request.Files.Count; i++)
                {
                    var f = Request.Files[i];
                    if (f != null && f.ContentLength > 0)
                    {
                        var fileName = FileHelpers.GenerateFilename(movie.Title, f.FileName);
                        var photoUrl = Path.Combine(
                            Server.MapPath(movie.Folder), fileName);
                        f.SaveAs(photoUrl);
                        movie.Photos.Add(new PhotoPathDto
                        {
                            Path = photoUrl
                        });
                    }
                }
                _movieService.AddPhotosToMovie(movie);
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("AddPhotoToFilm", new { id = movie.MovieId }));
        }