示例#1
0
        public IActionResult Edit(Guid id, PortifolioViewModel 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));
                    }
                    PortifolioItem portifolioItem = new PortifolioItem
                    {
                        Id          = model.Id,
                        Projectname = model.Projectname,
                        Description = model.Description,
                        ImageUrl    = model.File.FileName,
                    };
                    _porifolio.Entity.Update(portifolioItem);
                    _porifolio.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PortifolioItemExists(model.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
示例#2
0
 public async Task <IActionResult> Create(PortifolioViewModel 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));
         }
         PortifolioItem portifolioItem = new PortifolioItem
         {
             Projectname = model.Projectname,
             Description = model.Description,
             ImageUrl    = model.File.FileName,
         };
         _porifolio.Entity.Insert(portifolioItem);
         _porifolio.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(model));
 }
示例#3
0
        // GET: PortifolioItems/Edit/5
        public IActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var portifolioItem = _porifolio.Entity.GetById(id);

            if (portifolioItem == null)
            {
                return(NotFound());
            }
            PortifolioViewModel portifolioViewModel = new PortifolioViewModel
            {
                Id          = portifolioItem.Id,
                Description = portifolioItem.Description,
                Projectname = portifolioItem.Projectname,
                ImageUrl    = portifolioItem.ImageUrl,
            };

            return(View(portifolioViewModel));
        }