Example #1
0
        public IActionResult Edit(SlideShow aSlideShow, IFormFile photo, string pto)
        {
            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 = pto;
                }

                bool isUpdate = _iSlideShowManager.Update(aSlideShow);

                if (isUpdate)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.ErrorMessage = "Slide Show update failed! Try again.";
                }
            }

            return(View(aSlideShow));
        }
Example #2
0
        public async Task <IActionResult> Update(SlideShowViewModel slideShowViewModel, IFormFile photo, string pto)
        {
            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 = pto;
                }

                SlideShow updateSlideShow = _iMapper.Map <SlideShow>(slideShowViewModel);
                bool      isAdd           = await _iSlideShowManager.Update(updateSlideShow);

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