public ActionResult QAForStyleFromDialog(Int32 apprenticeshipId) { 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(apprenticeshipId); if (apprenticeship == null || apprenticeship.ProviderId != provider.ProviderId) { return(HttpNotFound()); } AddEditApprenticeshipQAForStyleModel model = new AddEditApprenticeshipQAForStyleModel { ApprenticeshipId = apprenticeshipId }; // Get Lookups GetLookups(model); return(View(model)); }
private void GetLookups(AddEditApprenticeshipQAForStyleModel model) { model.QAStyleFailureReasons = db.QAStyleFailureReasons.Where(x => x.RecordStatusId == (Int32)Constants.RecordStatus.Live).ToList(); List <SelectListItem> selectListItems = new List <SelectListItem> { new SelectListItem { Value = "1", Text = AppGlobal.Language.GetText(this, "Yes", "Yes") }, new SelectListItem { Value = "0", Text = AppGlobal.Language.GetText(this, "No", "No") }, }; ViewBag.YesNo = new SelectList(selectListItems, "Value", "Text", !String.IsNullOrEmpty(model.Passed) ? null : model.Passed == "1" ? "Yes" : "No"); }
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)); }