Beispiel #1
0
        public ActionResult AddPhotoToDirectorPost(int id)
        {
            var director = _directorDataProvider.GetDirectorDtoById(id);

            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];
                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Helper.GetRandomCharacters() + director.Name + Path.GetFileName(file.FileName);
                    director.PhotoUrl = Path.Combine(
                        Server.MapPath(director.Folder), fileName);
                    file.SaveAs(director.PhotoUrl);
                }
                var phototsList = new List <PhotoPathDto>();
                for (var i = 0; i < Request.Files.Count; i++)
                {
                    var f = Request.Files[i];
                    if (f.ContentLength > 0)
                    {
                        var fileName = Helper.GetRandomCharacters() + director.Name + Path.GetFileName(f.FileName);
                        phototsList.Add(new PhotoPathDto()
                        {
                            Path = Path.Combine(
                                Server.MapPath(director.Folder), fileName)
                        });
                        f.SaveAs(Path.Combine(
                                     Server.MapPath(director.Folder), fileName));
                    }
                }
                _directorService.AddPhotosToDirector(director, phototsList);

                return(RedirectToAction("Index"));
            }
            else
            {
                var addPhotoToDirectorViewModel = new AddPhotoToDirectorViewModel()
                {
                    Director = director
                };
                return(View(addPhotoToDirectorViewModel));
            }
        }