Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(EditModelBlog model)
        {
            //if (model.Id != blog.Id)
            //{
            //    return NotFound();
            //}

            if (ModelState.IsValid)
            {
                Blog blog = _context.Blogs.Find(model.Id);
                blog.Text  = model.Text;
                blog.Title = model.Title;
                if (model.Photo != null)
                {
                    if (model.ExistPhotoPath != null)
                    {
                        string filepath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistPhotoPath);
                        System.IO.File.Delete(filepath);
                    }
                    blog.Photo = ProccedFileUpload(model);
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        // GET: Control/Blogs/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var blog = await _context.Blogs.FindAsync(id);

            if (blog == null)
            {
                return(NotFound());
            }
            EditModelBlog modelBlog = new EditModelBlog();

            modelBlog.ExistPhotoPath = blog.Photo;
            modelBlog.Text           = blog.Text;
            modelBlog.Title          = blog.Title;
            return(View(modelBlog));
        }