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));

                    PortfolioItems portfolioItems = new PortfolioItems
                    {
                        ProjectName = model.ProjectName,
                        Description = model.Description,
                        ImageUrl    = model.File.FileName
                    };
                    _portfolio.Entity.Insert(portfolioItems);
                    _portfolio.Save();
                }
                else
                {
                    PortfolioItems portfolioItems = new PortfolioItems
                    {
                        ProjectName = model.ProjectName,
                        Description = model.Description,
                        ImageUrl    = "Avatar.jpg"
                    };
                    _portfolio.Entity.Insert(portfolioItems);
                    _portfolio.Save();
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
        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));

                        PortfolioItems portfolioItems = new PortfolioItems
                        {
                            Id          = model.Id,
                            ProjectName = model.ProjectName,
                            Description = model.Description,
                            ImageUrl    = model.File.FileName
                        };
                        _portfolio.Entity.Update(portfolioItems);
                        _portfolio.Save();
                    }
                    else
                    {
                        PortfolioItems portfolioItems = new PortfolioItems
                        {
                            Id          = model.Id,
                            ProjectName = model.ProjectName,
                            Description = model.Description,
                            ImageUrl    = model.ImageUrl
                        };
                        _portfolio.Entity.Update(portfolioItems);
                        _portfolio.Save();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PortfolioItemsExists(model.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Beispiel #3
0
 public double Value()
 {
     return(PortfolioItems.Sum(s => (s as LivePortfolioItem).Value()));
 }