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

            if (ModelState.IsValid)
            {
                try
                {
                    if (model.File != null)
                    {
                        string upload   = Path.Combine(_hosting.WebRootPath, @"img\portfolio");
                        string fullPath = Path.Combine(upload, model.File.FileName);
                        model.File.CopyTo(new FileStream(fullPath, FileMode.Create));
                    }
                    PortfolioItem portfolioItem = new PortfolioItem
                    {
                        Id          = model.Id,
                        ProjectName = model.ProjectName,
                        Description = model.Description,
                        ImageUrl    = model.File.FileName
                    };
                    _portofolio.Entity.Update(portfolioItem);
                    _portofolio.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PortfolioItemExists(model.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
コード例 #2
0
 public IActionResult Create(PortoflioViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.File != null)
         {
             string upload   = Path.Combine(_hosting.WebRootPath, @"img\portfolio");
             string fullPath = Path.Combine(upload, model.File.FileName);
             model.File.CopyTo(new FileStream(fullPath, FileMode.Create));
         }
         PortfolioItem portfolioItem = new PortfolioItem
         {
             ProjectName = model.ProjectName,
             Description = model.Description,
             ImageUrl    = model.File.FileName
         };
         _portofolio.Entity.Insert(portfolioItem);
         _portofolio.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 = _portofolio.Entity.GetById(id);

            if (portfolioItem == null)
            {
                return(NotFound());
            }
            PortoflioViewModel portoflioViewModel = new PortoflioViewModel
            {
                Id          = portfolioItem.Id,
                ProjectName = portfolioItem.ProjectName,
                Description = portfolioItem.Description,
                ImageUrl    = portfolioItem.ImageUrl
            };

            return(View(portoflioViewModel));
        }