I have the following code within my controller method to provide data to the List View of membership Types:
[HttpGet]
public ActionResult SelectMembershipType(int clubId)
{
//Populate the list
var membershipTypes = from s in db.MembershipTypes
where (s.ClubId == clubId && s.Dormant == false)
orderby s.Type
select s;
//Generate the ViewModel with the appropriate membership types
var viewModel = membershipTypes.Select(t => new SelectMembershipTypeViewModel
{
//Select appropriate Cost based on current month
if(DateTime.Now.Month == t.ReducedMonth)
{
Cost = t.ReducedCost;
}
else
{
Cost = t.Cost;
}
ClubId = club.ClubId,
Name = club.Name,
MembershipName = t.Type,
MembershipType = t.MembershipTypeClassification.Type,
MembershipTypeId = t.MembershipTypeId,
});
return View(viewModel);
}
The if statement Ive put in doesn't work it throws several errors. I'm trying to apply an if Statement to the value for Cost i.e. if todays month is equal to the ReducedMonth in the database for each membership Type make the value of Cost equal to the Membership Types ReducedCost value, if not make it equal to its Cost instead. Each MembershipType can have different Reduced Months and Costs
I'm not sure of the correct syntax to code this correctly