public AddEditApprenticeshipQAForStyleModel(ApprenticeshipQAStyle apprenticeshipQAStyle) : this() { this.ApprenticeshipQAStyleId = apprenticeshipQAStyle.ApprenticeshipQAStyleId; this.ApprenticeshipId = apprenticeshipQAStyle.ApprenticeshipId; this.Passed = apprenticeshipQAStyle.Passed ? "1" : "0"; foreach (QAStyleFailureReason fr in apprenticeshipQAStyle.QAStyleFailureReasons) { this.SelectedStyleFailureReasons.Add(fr.QAStyleFailureReasonId); } }
public ActionResult QAForStyleFromDialog(AddEditApprenticeshipQAForStyleModel model) { if (userContext.ContextName != UserContext.UserContextName.Provider) { return(HttpNotFound()); } Provider provider = db.Providers.Find(userContext.ItemId); if (provider == null) { return(HttpNotFound()); } Apprenticeship apprenticeship = db.Apprenticeships.Find(model.ApprenticeshipId); if (apprenticeship == null || apprenticeship.ProviderId != provider.ProviderId) { return(HttpNotFound()); } // If passed compliance checks is No then failure reasons should be mandatory if (model.Passed == "0" && model.SelectedStyleFailureReasons.Count == 0) { ModelState.AddModelError("SelectedStyleFailureReasons", AppGlobal.Language.GetText(this, "SelectedStyleFailureReasonsMandatory", "Please select a reason for failure")); } else if (model.Passed == "1" && model.SelectedStyleFailureReasons.Count > 0) { ModelState.AddModelError("Passed", AppGlobal.Language.GetText(this, "CannotPassQAWithFailureReasons", "Passed style checks should only be Yes when no failure reasons have been selected")); } if (ModelState.IsValid) { ApprenticeshipQAStyle QA = model.ToEntity(db); apprenticeship.ApprenticeshipQAStyles.Add(QA); db.Entry(apprenticeship).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Json(new ApprenticeshipQAForStyleJsonModel(QA))); } // Populate drop downs GetLookups(model); return(View(model)); }
public static ApprenticeshipQAStyle ToEntity(this AddEditApprenticeshipQAForStyleModel model, ProviderPortalEntities db) { Apprenticeship apprenticeship = db.Apprenticeships.Find(model.ApprenticeshipId); ApprenticeshipQAStyle QA; if (model.ApprenticeshipQAStyleId.HasValue) { QA = db.ApprenticeshipQAStyles.Find(model.ApprenticeshipQAStyleId); } else { QA = new ApprenticeshipQAStyle { ApprenticeshipId = model.ApprenticeshipId, CreatedByUserId = Permission.GetCurrentUserId(), CreatedDateTimeUtc = DateTime.UtcNow, TextQAd = apprenticeship.MarketingInformation }; } // If adding new properties here please also add them to the bulk upload // otherwise data loss will occur. Bulk upload deletes and re-creates // apprenticeships. It also deletes all QA records associated with // apprenticeships and these have to be re-added after the bulk upload has finished. // This is handled in the LoadApprenticeships method of the ApprenticeshipConverter class QA.Passed = model.Passed == "1"; QA.DetailsOfQA = model.DetailsOfQA; // Add the failure reasons foreach (Int32 frId in model.SelectedStyleFailureReasons) { QAStyleFailureReason fr = db.QAStyleFailureReasons.Find(frId); if (fr != null) { QA.QAStyleFailureReasons.Add(fr); } } return(QA); }
public ApprenticeshipQAForStyleJsonModel(ApprenticeshipQAStyle apprenticeshipQAStyle) : this() { this.ApprenticeshipQAForComplianceId = apprenticeshipQAStyle.ApprenticeshipQAStyleId; this.Passed = apprenticeshipQAStyle.Passed; }