CurlyRed(Serzhio)
Hello. I am facing an issue with null exception after calling OnPost method in my razor pages site.
When i call method OnGet i load all of the information about property. public void OnGet(int? id)
{
Property = pS.GetProperty(id);
DownPayment = Property.Price * 0.2m;
MaximumLoan = Property.Price - DownPayment;
}
But when i call method OnPost
public IActionResult OnPostCalculateMortgage(int? id)
{
if (!ModelState.IsValid)
{
return Page();
}
// Determine which strategy to use based on the amount to be borrowed
ICalculateStrategy strategy;
if (AmountToBorrow > MaximumLoan * 0.5m)
{
strategy = new FixedRateStrategy();
}
else
{
strategy = new FloatingRateStrategy();
}
// Set the strategy and calculate the monthly payments
Property.Calculator.SetStrategy(strategy);
try
{
// Calculate the monthly payments
List<string> paymentSchedule = Property.Calculator.CalculateMonthlyPayment(AmountToBorrow, LoanTerm);
// Add the payment schedule to ViewData to display in the page
ViewData["PaymentSchedule"] = paymentSchedule;
}
catch (InvalidOperationException ex)
{
// Handle exceptions and add error messages to ModelState
ModelState.AddModelError(string.Empty, "An error occurred while calculating the mortgage.");
}
catch (NegativeLoanTermException ex)
{
ModelState.AddModelError(string.Empty, "Loan term must be positive and at least 12 months.");
}
catch (NegativePrincipalException ex)
{
ModelState.AddModelError(string.Empty, "The amount to borrow must be greater than zero.");
}
// Return the page with the payment schedule or error messages
return Page();
}
60 replies
UnitTests. Dont run despite correct setup
I really dont understand what is the issue. I have ClassLibrary and UnitTest project, i set dependancy where UnitTest depend on ClassLibrary but they just dont run, though all builds are successful
1 replies
UML class diagram. Class relationships.
I have a parent class User and child classes Manager and Client. Then I have class Property, Offer and Inquiry. Each Manager must have a list of Inquiries and Offers that he is responsible for, while each Client must have a list of Inquiries and Offers he sent. Each Inquiry or Offer must have Client, Manager and Property objects init. And here is the question, when I log in a Manager to application, I log him in with lists of Inquiries and Offers and then each of the Offer/Inquiry populates with new Manager that has a list of Inquiry/Offer. I feel like this going to be looped and the only solution I came up with is to log in Manager or Client with null lists and then load ALL Inquiries/Offers and loop through them to find matching ID of currently logged in Manager/Client and store them in a Manager/Client lists. Although this approach might be slow in terms of looping, but I see only this way to solve my issue. Will be happy to any kind of comment. Thank you
8 replies