コード例 #1
0
        // GET: Control/GalleryPhotos/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var galleryPhotos = await _context.GalleryPhotos.FindAsync(id);

            if (galleryPhotos == null)
            {
                return(NotFound());
            }
            EditGalleryPhoto modelGallery = new EditGalleryPhoto();

            modelGallery.ExistPhotoPath = galleryPhotos.Image;

            return(View(modelGallery));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(EditGalleryPhoto model)
        {
            if (ModelState.IsValid)
            {
                GalleryPhotos gphoto = _context.GalleryPhotos.Find(model.Id);

                if (model.Photo != null)
                {
                    if (model.ExistPhotoPath != null)
                    {
                        string filepath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistPhotoPath);
                        System.IO.File.Delete(filepath);
                    }
                    gphoto.Image = ProccedFileUpload(model);
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }