コード例 #1
0
        public async Task <IActionResult> Create(SlideShowViewModel slideShowViewModel, IFormFile photo)
        {
            if (ModelState.IsValid)
            {
                if (photo != null)
                {
                    string nameAndPath = Path.Combine(_iHostingEnvironment.WebRootPath
                                                      + "/slide_show", Path.GetFileName(photo.FileName));
                    await photo.CopyToAsync(new FileStream(nameAndPath, FileMode.Create));

                    slideShowViewModel.Photo = "slide_show/" + photo.FileName;
                }

                if (photo == null)
                {
                    slideShowViewModel.Photo = "slide_show/NoImageFound.jpg";
                }

                SlideShow createSlideShow = _iMapper.Map <SlideShow>(slideShowViewModel);
                bool      isAdd           = await _iSlideShowManager.Create(createSlideShow);

                if (isAdd)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.ErrorMessage = "Failed to Save Slide-Show";
                }
            }
            return(View(slideShowViewModel));
        }