Exemple #1
0
        public IActionResult Add(SlideShow aSlideShow, IFormFile photo)
        {
            if (ModelState.IsValid)
            {
                if (photo != null)
                {
                    string nameAndPath = Path.Combine(_iHostingEnvironment.WebRootPath
                                                      + "/SlideShow", Path.GetFileName(photo.FileName));
                    photo.CopyToAsync(new FileStream(nameAndPath, FileMode.Create));
                    aSlideShow.Photo = "SlideShow/" + photo.FileName;
                }

                if (photo == null)
                {
                    aSlideShow.Photo = "SlideShow/NoImageFound.png";
                }

                bool isAdd = _iSlideShowManager.Add(aSlideShow);

                if (isAdd)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.ErrorMessage = "Slide Show save has been failed!";
                }
            }

            return(View(aSlideShow));
        }