예제 #1
0
        public async Task <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));
                }

                ProtfolioItem portfolioItem = new ProtfolioItem
                {
                    ProjectName = model.ProjectName,
                    Description = model.Description,
                    ImageUrl    = model.File.FileName
                };

                _portfolio.Entity.Insert(portfolioItem);
                _portfolio.Save();
                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
예제 #2
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));
                    }
                    ProtfolioItem porfolioItem = new ProtfolioItem
                    {
                        Id = model.Id,

                        Description = model.Description,

                        ImageUrl = model.ImageUrl,

                        ProjectName = model.ProjectName,
                    };

                    _portfolio.Entity.Update(porfolioItem);
                    _portfolio.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProfolioItemExists(model.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }