//private CourseDetails value; /// <summary> /// Main view model constructor /// </summary> /// <param name="value"></param> public CourseDetailViewModel(ICourseItemDetail value, string distance, string postcode, int?oppid) { if (value != null) { CourseId = value.Coursedetails.CourseId;// Opportunity.Id; CourseTitle = value.Coursedetails.CourseTitle; CourseSummary = value.Coursedetails.CourseSummary; QualificationLevel = value.Coursedetails.QualificationLevel; StudyMode = value.Opportunities[0].StudyMode; AttendanceMode = value.Opportunities[0].AttendanceMode; AttendencePattern = value.Opportunities[0].AttendancePattern; ProviderName = value.Provider.Name; Location = (value.Opportunities[0].HasVenue) ? value.Opportunities[0].Venue.Address.ToString() : value.Opportunities[0].Region; Distance = (value.Opportunities[0].HasVenue && value.Opportunities[0].Venue.Distance.HasValue) ? value.Opportunities[0].Venue.Distance.Value.ToString("0.0") : distance; StartDate = value.Opportunities[0].StartDate.ToString(); Duration = value.Opportunities[0].Duration.ToString(); AwardingBody = value.Coursedetails.AwardingBody; EntryRequirements = value.Coursedetails.EntryRequirements; AssessmentMethod = value.Coursedetails.AssessmentMethod; EquipmentRequired = value.Coursedetails.EquipmentRequired; URL = Uri.IsWellFormedUriString(value.Coursedetails.URL, UriKind.Absolute) ? value.Coursedetails.URL : string.Empty; BookingURL = Uri.IsWellFormedUriString(value.Coursedetails.BookingURL, UriKind.Absolute) ? value.Coursedetails.BookingURL : string.Empty; TariffRequired = value.Coursedetails.TariffRequired; LADID = value.Coursedetails.LADID; QualificationReferenceAuthority = value.Coursedetails.QualificationReferenceAuthority; QualificationReference = value.Coursedetails.QualificationReference; QualificationTitle = value.Coursedetails.QualificationTitle; Level2EntitlementCategoryDesc = value.Coursedetails.Level2EntitlementCategoryDesc; Level3EntitlementCategoryDesc = value.Coursedetails.Level3EntitlementCategoryDesc; SectorLeadBodyDesc = value.Coursedetails.SectorLeadBodyDesc; AccreditationStartDate = value.Coursedetails.AccreditationStartDate; AccreditationEndDate = value.Coursedetails.AccreditationEndDate; CertificationEndDate = value.Coursedetails.CertificationEndDate; CreditValue = value.Coursedetails.CreditValue; QCAGuidedLearningHours = value.Coursedetails.QCAGuidedLearningHours; SkillsForLifeTypeDesc = value.Coursedetails.SkillsForLifeTypeDesc; Venues = value.Venues != null?value.Venues.AsEnumerable().Cast <Venue>().ToList() : null; Provider = (Provider)value.Provider; //Load Opportunities, passing in the venue list for linking, and the opportunityID to set order Opportunities = LoadOpportunities(value, Venues, oppid); } Postcode = postcode; }
private List <Opportunity> LoadOpportunities(ICourseItemDetail value, List <Venue> venues, int?oppid = null) { List <Opportunity> data = value.Opportunities.AsEnumerable().Cast <Opportunity>().OrderBy(o => o.StartDate.Date).ToList(); //Check to see if we have venus and then load if (null != venues && venues.Count > 0) { foreach (Opportunity opp in data) { if (opp.ItemsElementName[0] == ItemChoice.VenueID) { opp.Venue = (IVenue)venues.FirstOrDefault(v => v.VenueId == opp.Items[0]); } } if (null != oppid && oppid.HasValue && oppid.Value > 0) { return(data.OrderByDescending(x => x.Id == oppid.Value).ToList()); } } return(data); }