Пример #1
0
        public IActionResult EditHomeContent(int?id, EditHomeContentViewModel model)
        {
            if (id == null)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    if (model.File != null)
                    {
                        string upload   = Path.Combine(_hosting.WebRootPath, @"image");
                        string fullpath = Path.Combine(upload, model.File.FileName);
                        model.File.CopyTo(new FileStream(fullpath, FileMode.Create));
                        model.Image = model.File.FileName;
                    }

                    var homecontent = new HomeContent
                    {
                        Id        = model.Id,
                        Paragraph = model.Paragraph,
                        Image     = model.Image
                    };
                    _context.Entry(homecontent).State = EntityState.Modified;
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(RedirectToAction(nameof(HomeContentIndex)));
            }
            return(View(model));
        }
Пример #2
0
        public IActionResult EditHomeContent(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var exist = _context.HomeContents.Single(h => h.Id == id);

            if (exist == null)
            {
                return(NotFound());
            }
            EditHomeContentViewModel viewmodel = new EditHomeContentViewModel
            {
                Paragraph = exist.Paragraph,
                Image     = exist.Image
            };

            return(View(viewmodel));
        }