public ActionResult Asset(AssetViewModel assetViewModel, string direction) { SBTAsset asset = assetViewModel.Asset; SessionViewModel viewModel = GetViewModel(); if (viewModel.Assets.Any(x => x.Id == asset.Id)) { // grab reference to existing assset var existingAsset = viewModel.Assets.FirstOrDefault(a => a.Id == asset.Id); // remove it from collection viewModel.Assets.Remove(existingAsset); // update collection with replacement asset viewModel.Assets.Add(asset); } else { asset.Id = Guid.NewGuid(); viewModel.Assets.Add(asset); } Session["SBT"] = viewModel; if (!string.IsNullOrEmpty(direction)) { return(RedirectToAction(direction)); } assetViewModel.CatIBTL = GetIBTLCat(asset.assetCatIBTL); ViewBag.catPiefaos = GetPIEFAOS(); ViewBag.catIBTL = GetIBTLCat(asset.assetCatIBTL); ViewBag.catIBTLSub = GetIBTLSubCat(); return(View(assetViewModel)); }
// ------------------------------------------------------------------------------------------------------------------------------- // GET: SecBase/Asset public ActionResult Asset(Guid?id) { var viewModel = GetViewModel(); SBTAsset asset = new SBTAsset(); if (id.HasValue && id != Guid.Empty && viewModel.Assets.Any(x => x.Id == id)) { asset = viewModel.Assets.First(x => x.Id == id); } var vm = new AssetViewModel(); vm.Asset = asset; vm.CatIBTL = GetIBTLCat(asset.assetCatIBTL); ViewBag.catPiefaos = GetPIEFAOS(); //ViewBag.catIBTL = GetIBTLCat(asset.assetCatIBTL); ViewBag.catIBTLSub = GetIBTLSubCat(); return(View(vm)); }