Question
please help me fix this bug on ASP.NET C#. Text does not automatically revert after a failed update/creation of a new Portfolio public ManagePortfolioGridViewModel UpdatePortfolio(ManagePortfolioGridViewModel
please help me fix this bug on ASP.NET C#. Text does not automatically revert after a failed update/creation of a new Portfolio
public ManagePortfolioGridViewModel UpdatePortfolio(ManagePortfolioGridViewModel vm) { using var uow = new UnitOfWork(new MobilebdContext()); var existingPortfolioWithSameName = uow.Portfolios.Find(t => t.Name == vm.Name.Trim()) .ToList();
var existingPortfolioWithSameAbbreviation = uow.Portfolios.Find(t => t.Abbreviation == vm.Abbreviation.Trim()) .ToList();
if (existingPortfolioWithSameName.Any()) { if (existingPortfolioWithSameName.Count != 1) { throw new Exception("Multiple Portfolios with this name already exists."); }
var isSamePortfolio = existingPortfolioWithSameName[0].Id == vm.Id;
if (!isSamePortfolio) { throw new Exception("A Portfolio with this name already exists."); } } if (existingPortfolioWithSameAbbreviation.Any()) { if (existingPortfolioWithSameAbbreviation.Count != 1) { throw new Exception("Multiple Portfolios with this abbriviation already exists."); }
var isSamePortfolio = existingPortfolioWithSameAbbreviation[0].Id == vm.Id;
if (!isSamePortfolio) { throw new Exception("A Portfolio with this abbriviation already exists."); } }
var newPortfolio = uow.Portfolios.Get(vm.Id);
newPortfolio.Name = vm.Name; newPortfolio.RevenueTarget = vm.RevenueTarget; newPortfolio.Abbreviation = vm.Abbreviation;
uow.Complete();
return vm; }
public ManagePortfolioGridViewModel CreatePortfolio(ManagePortfolioGridViewModel vm) { using var uow = new UnitOfWork(new MobilebdContext()); var existingPortfolioWithSameName = uow.Portfolios.Find(t => t.Name == vm.Name.Trim()); var existingPortfolioWithSameAbbreviation = uow.Portfolios.Find(t => t.Abbreviation == vm.Abbreviation.Trim());
if (existingPortfolioWithSameName.Any()) { throw new Exception("A Portfolio with this name already exists."); } if (existingPortfolioWithSameAbbreviation.Any()) { throw new Exception("A Portfolio with this abbreviation already exists."); }
var newPortfolio = new Portfolio { Name = vm.Name, RevenueTarget = vm.RevenueTarget, Abbreviation = vm.Abbreviation };
uow.Portfolios.Add(newPortfolio); uow.Complete();
vm.Id = newPortfolio.Id; vm.Name = newPortfolio.Name; vm.RevenueTarget = newPortfolio.RevenueTarget; vm.Abbreviation = newPortfolio.Abbreviation;
return vm; }
public ActionResult ManagePortfolioGridUpdate([DataSourceRequest] DataSourceRequest request, ManagePortfolioGridViewModel vm) { try { var result = _adminBll.UpdatePortfolio(vm); return Json(new[] { result }.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
} catch (Exception e) { Log.Error(e.Message); ModelState.AddModelError(string.Empty, e.Message); return Json(new[] { vm }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); }
}
public ActionResult ManagePortfolioGridCreate([DataSourceRequest] DataSourceRequest request, ManagePortfolioGridViewModel vm) { try { var result =_adminBll.CreatePortfolio(vm); return Json(new[] { result }.ToDataSourceResult(request, ModelState));
} catch (Exception e) { Log.Error(e.Message);
ModelState.AddModelError(string.Empty, e.Message); return Json(new[] { vm }.ToDataSourceResult(request, ModelState));
}
}
+ Create New Portfolio Portfolio Name Portfolio Abbreviation Y Revenue Target Information Maintenance IM $0.00 Edit IT/Cloud/Cyber IT $0.00 Edit Professional Services PS $0.00 Edit Software Development SD $0.00 Edit Technical/Engineering Services ET $0.00 Edit testing2 $0.00 Edit testing2 T2 $100.00 Edit testing3 T3 $0.00 Edit USDA Agri $0.00 Edit
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started