コード例 #1
0
        public IActionResult Edit(Guid id, PortFolioViewModel model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (model.File != null)
                    {
                        string uploads  = Path.Combine(_hosting.WebRootPath, @"img\portfolio");
                        string FullPath = Path.Combine(uploads, model.File.FileName);
                        model.File.CopyTo(new FileStream(FullPath, FileMode.Create));
                    }
                    PortFolioItem portFolio = new PortFolioItem
                    {
                        Id          = model.Id,
                        ProjectName = model.ProjectName,
                        Description = model.Description,
                        ImageUrl    = model.File.FileName
                    };
                    _portfolio.Entity.Update(portFolio);
                    _portfolio.Save();
                }

                catch (DbUpdateConcurrencyException)
                {
                    if (!PortFolioItemExists(model.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
コード例 #2
0
 public IActionResult Create(PortFolioViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.File != null)
         {
             string uploads  = Path.Combine(_hosting.WebRootPath, @"img\portfolio");
             string FullPath = Path.Combine(uploads, model.File.FileName);
             model.File.CopyTo(new FileStream(FullPath, FileMode.Create));
         }
         PortFolioItem portFolio = new PortFolioItem
         {
             ProjectName = model.ProjectName,
             Description = model.Description,
             ImageUrl    = model.File.FileName
         };
         _portfolio.Entity.Insert(portFolio);
         _portfolio.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(model));
 }
コード例 #3
0
        // GET: PortFolioItems/Edit/5
        public IActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var portFolioItem = _portfolio.Entity.GetById(id);

            if (portFolioItem == null)
            {
                return(NotFound());
            }

            PortFolioViewModel portFolioView = new PortFolioViewModel
            {
                Id          = portFolioItem.Id,
                ProjectName = portFolioItem.ProjectName,
                Description = portFolioItem.Description,
                ImageUrl    = portFolioItem.ImageUrl
            };

            return(View(portFolioView));
        }