public static List <String> GetWarningMessages(this AddEditApprenticeshipViewModel model, ProviderPortalEntities db) { List <String> messages = new List <String>(); if (!String.IsNullOrWhiteSpace(model.Url) && !UrlHelper.UrlIsReachable(model.Url)) { messages.Add(String.Format(AppGlobal.Language.GetText("AddEditApprenticeshipViewModel_Edit_UrlNotReachable", "The web address for {0} returns a response that suggests this page may not exist. Please check that the web address entered is correct."), AppGlobal.Language.GetText("AddEditApprenticeshipViewModel_DisplayName_Url", "Your Apprenticeship Website Page"))); } if (!String.IsNullOrWhiteSpace(model.ContactWebsite) && !UrlHelper.UrlIsReachable(model.ContactWebsite)) { messages.Add(String.Format(AppGlobal.Language.GetText("AddEditApprenticeshipViewModel_Edit_UrlNotReachable", "The web address for {0} returns a response that suggests this page may not exist. Please check that the web address entered is correct."), AppGlobal.Language.GetText("AddEditApprenticeshipViewModel_DisplayName_ContactWebsite", @"Your Apprenticeship Website ""Contact Us"" Page"))); } return(messages); }
public static Apprenticeship ToEntity(this AddEditApprenticeshipViewModel model, ProviderPortalEntities db) { var userContext = UserContext.GetUserContext(); var userId = Permission.GetCurrentUserId(); if (!userContext.IsProvider()) { return(null); } Apprenticeship apprenticeship = model.ApprenticeshipId != 0 ? db.Apprenticeships.FirstOrDefault( x => x.ApprenticeshipId == model.ApprenticeshipId && x.ProviderId == userContext.ItemId.Value) : null; apprenticeship = apprenticeship ?? new Apprenticeship { CreatedByUserId = userId, CreatedDateTimeUtc = DateTime.UtcNow, ProviderId = userContext.ItemId.Value, RecordStatusId = (int)Constants.RecordStatus.Pending }; apprenticeship.ModifiedByUserId = userId; apprenticeship.ModifiedDateTimeUtc = DateTime.UtcNow; apprenticeship.AddedByApplicationId = (int)Constants.Application.Portal; apprenticeship.MarketingInformation = Markdown.Sanitize(model.MarketingInformation); apprenticeship.Url = UrlHelper.GetFullUrl(model.Url); apprenticeship.ContactTelephone = model.ContactTelephone; apprenticeship.ContactEmail = model.ContactEmail; apprenticeship.ContactWebsite = UrlHelper.GetFullUrl(model.ContactWebsite); Apprenticeship frameworkOrStandard = ApprenticeshipExtensions.DecodeSearchFrameworkOrStandard(model.FrameworkOrStandardId) ?? ApprenticeshipExtensions.DecodeSearchFrameworkOrStandardByName(model.FrameworkOrStandard); if (frameworkOrStandard != null) { apprenticeship.StandardCode = frameworkOrStandard.StandardCode; apprenticeship.Version = frameworkOrStandard.Version; apprenticeship.FrameworkCode = frameworkOrStandard.FrameworkCode; apprenticeship.ProgType = frameworkOrStandard.ProgType; apprenticeship.PathwayCode = frameworkOrStandard.PathwayCode; } return(apprenticeship); }
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 bool Validate(this AddEditApprenticeshipViewModel model, ProviderPortalEntities db, ModelStateDictionary modelState) { if (modelState["FrameworkOrStandard"].Errors.Count == 0) { Apprenticeship frameworkOrStandard = ApprenticeshipExtensions.DecodeSearchFrameworkOrStandard(model.FrameworkOrStandardId) ?? ApprenticeshipExtensions.DecodeSearchFrameworkOrStandardByName(model.FrameworkOrStandard); if (frameworkOrStandard == null) { modelState.AddModelError("FrameworkOrStandard", AppGlobal.Language.GetText("Apprenticeship_Edit_FrameworkOrStandardRequired", "The Framework / Standard Name field is required.")); } else { Int32 providerId = UserContext.GetUserContext().ItemId ?? 0; Apprenticeship app = db.Apprenticeships.FirstOrDefault(x => x.ProviderId == providerId && x.StandardCode == frameworkOrStandard.StandardCode && x.Version == frameworkOrStandard.Version && x.FrameworkCode == frameworkOrStandard.FrameworkCode && x.ProgType == frameworkOrStandard.ProgType && x.PathwayCode == frameworkOrStandard.PathwayCode && (model.ApprenticeshipId == 0 || x.ApprenticeshipId != model.ApprenticeshipId)); if (app != null) { modelState.AddModelError("FrameworkOrStandard", AppGlobal.Language.GetText("Apprenticeship_Create_FrameworkOrStandardMustBeUnique", "The Framework / Standard Name supplied is already in use.")); } } } return(modelState.IsValid); }
public static AddEditApprenticeshipViewModel Populate(this AddEditApprenticeshipViewModel model, ProviderPortalEntities db) { // Create new apprenticeship if (model == null) { model = new AddEditApprenticeshipViewModel(); } model.RecordStatusId = (int)Constants.RecordStatus.Pending; UserContext.UserContextInfo uc = UserContext.GetUserContext(); if (uc.IsProvider()) { Provider provider = db.Providers.Find(uc.ItemId); if (provider != null) { model.DisplayNotPublishedBanner = !provider.ApprenticeshipContract; } } return(model); }