public static AddEditApprenticeshipViewModel Populate(this AddEditApprenticeshipViewModel model, int id,
                                                              ProviderPortalEntities db)
        {
            var apprenticeship = new Apprenticeship();

            if (id > 0)
            {
                var userContext = UserContext.GetUserContext();
                if (userContext.IsProvider())
                {
                    apprenticeship = db.Apprenticeships.FirstOrDefault(
                        x =>
                        x.ApprenticeshipId == id &&
                        x.ProviderId == userContext.ItemId.Value);
                }
            }
            model = new AddEditApprenticeshipViewModel
            {
                ApprenticeshipId      = apprenticeship.ApprenticeshipId,
                RecordStatusId        = apprenticeship.RecordStatusId,
                FrameworkOrStandardId = ApprenticeshipExtensions.GetFrameworkOrStandardId(apprenticeship),
                FrameworkOrStandard   = apprenticeship.ApprenticeshipDetails(),
                MarketingInformation  = apprenticeship.MarketingInformation,
                Url                       = UrlHelper.GetFullUrl(apprenticeship.Url),
                ContactEmail              = apprenticeship.ContactEmail,
                ContactTelephone          = apprenticeship.ContactTelephone,
                ContactWebsite            = UrlHelper.GetFullUrl(apprenticeship.ContactWebsite),
                DisplayNotPublishedBanner = !apprenticeship.Provider.ApprenticeshipContract,
                HasBeenQAdForCompliance   = apprenticeship.ApprenticeshipQACompliances.Any(),
                LastQAdForComplianceBy    = apprenticeship.ApprenticeshipQACompliances.Count == 0 ? null : apprenticeship.ApprenticeshipQACompliances.OrderByDescending(m => m.CreatedDateTimeUtc).First().AspNetUser.Name,
                LastQAdForComplianceOn    = apprenticeship.ApprenticeshipQACompliances.Count == 0 ? (DateTime?)null : apprenticeship.ApprenticeshipQACompliances.OrderByDescending(m => m.CreatedDateTimeUtc).First().CreatedDateTimeUtc,
                HasPassedComplianceChecks = apprenticeship.ApprenticeshipQACompliances.Count != 0 && apprenticeship.ApprenticeshipQACompliances.OrderByDescending(m => m.CreatedDateTimeUtc).First().Passed,
                HasBeenQAdForStyle        = apprenticeship.ApprenticeshipQAStyles.Any(),
                LastQAdForStyleBy         = apprenticeship.ApprenticeshipQAStyles.Count == 0 ? null : apprenticeship.ApprenticeshipQAStyles.OrderByDescending(m => m.CreatedDateTimeUtc).First().AspNetUser.Name,
                LastQAdForStyleOn         = apprenticeship.ApprenticeshipQAStyles.Count == 0 ? (DateTime?)null : apprenticeship.ApprenticeshipQAStyles.OrderByDescending(m => m.CreatedDateTimeUtc).First().CreatedDateTimeUtc,
                HasPassedStyleChecks      = apprenticeship.ApprenticeshipQAStyles.Count != 0 && apprenticeship.ApprenticeshipQAStyles.OrderByDescending(m => m.CreatedDateTimeUtc).First().Passed
            };
            var deliveryLocations = new DeliveryLocationListViewModel();

            model.DeliveryLocations = deliveryLocations.Populate(id, db);

            return(model);
        }
        public static DeliveryLocationListViewModel Populate(this DeliveryLocationListViewModel model,
                                                             int apprenticeshipId, ProviderPortalEntities db)
        {
            if (model == null)
            {
                model = new DeliveryLocationListViewModel();
            }

            model.Items = db.ApprenticeshipLocations
                          .Where(x => x.ApprenticeshipId == apprenticeshipId)
                          .Select(x => new DeliveryLocationListViewModelItem()
            {
                ApprenticeshipLocationId = x.ApprenticeshipLocationId,
                ProviderOwnLocationRef   = x.Location.ProviderOwnLocationRef,
                LocationName             = x.Location.LocationName,
                DeliveryModes            = x.DeliveryModes.Select(y => y.DeliveryModeName).OrderBy(y => y),
                Radius     = x.Radius,
                Status     = x.RecordStatu.RecordStatusName,
                LastUpdate = x.ModifiedDateTimeUtc ?? x.CreatedDateTimeUtc
            })
                          .OrderByDescending(x => x.LastUpdate)
                          .ToList();
            return(model);
        }