示例#1
0
        public async Task <IActionResult> EditPortfolioAsset(PortfolioAssetViewModel assetvm)
        {
            string returnurl      = assetvm.ReturnUrl;
            var    portfolioAsset = new PortfolioAsset
            {
                Id      = assetvm.Id,
                Caption = assetvm.Caption
            };

            if (assetvm.Asset == null)
            {
                portfolioAsset.Asset = assetvm.CurrentAsset;
            }
            else
            {
                if (!string.IsNullOrEmpty(assetvm.CurrentAsset))
                {
                    _fileManager.RemovePortfolioAsset(assetvm.CurrentAsset);
                }
                portfolioAsset.Asset = _fileManager.SavePortfolioAsset(assetvm.Asset);
            }
            if (portfolioAsset.Id > 0)
            {
                _repo.UpdatePortfolioAsset(portfolioAsset);
            }
            else
            {
                var item = _repo.GetPortfolioItemForAssets(assetvm.PortfolioItemId);
                portfolioAsset.PortfolioItem = item;
                _repo.AddPortfolioAsset(portfolioAsset);
            }
            if (await _repo.SaveChangesAsync())
            {
                return(LocalRedirect(returnurl));
            }
            else
            {
                return(View(portfolioAsset));
            }
        }
示例#2
0
 public IActionResult EditPortfolioAsset(int?id, int portfolioitemid, string returnurl)
 {
     if (id == null)
     {
         var vm = new PortfolioAssetViewModel()
         {
             PortfolioItemId = portfolioitemid,
             ReturnUrl       = returnurl
         };
         return(View(vm));
     }
     else
     {
         var portfolioAsset = _repo.GetPortfolioAsset((int)id);
         return(View(new PortfolioAssetViewModel
         {
             Id = portfolioAsset.Id,
             PortfolioItemId = portfolioitemid,
             CurrentAsset = portfolioAsset.Asset,
             Caption = portfolioAsset.Caption,
             ReturnUrl = returnurl
         }));
     }
 }