public ActionResult Delete(TeachingPeriod teachingPeriod) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.TeachingPeriod)) { return(RedirectToPermissionDenied()); } try { // Ensure no UnitOfferings are using this TeachingPeriod before attempting delete. if (UnitOfferingProcessor.SelectUnitOfferingCountForTeachingPeriod(teachingPeriod.TeachingPeriodId) > 0) { throw new DataException("Unable to delete Teaching Period. One or more Unit Offerings require it."); } // Attempt to Delete TeachingPeriod TeachingPeriodProcessor.DeleteTeachingPeriod(teachingPeriod.TeachingPeriodId); // Return to Index if Delete Successful return(RedirectToAction("Index")); } catch (Exception e) { //Show error ModelState.AddModelError("", e.Message); } // If any error return to View db.GetTeachingPeriod(teachingPeriod.TeachingPeriodId); return(View(db)); }
/// <summary> /// The main page of the TeachingPeriod controller /// Shows a list of all TeachingPeriods in the system /// </summary> /// <returns></returns> public ActionResult Index( ) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.TeachingPeriod)) { return(RedirectToPermissionDenied()); } //Set the page message ViewBag.Message = "Teaching Period List"; //db.GetTeachingPeriods( ); // Get all teaching periods from the database var teachingPeriodModels = TeachingPeriodProcessor.SelectTeachingPeriods( ); // Change the format of the year list List <TeachingPeriod> teachingPeriods = new List <TeachingPeriod>( ); foreach (var t in teachingPeriodModels) { teachingPeriods.Add(new TeachingPeriod(t)); } //Return the view, with the list of TeachingPeriods return(View(teachingPeriods)); }
/// <summary> /// Navigate to Details page for a Unit Offering /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Details(int id) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.UnitOffering)) { return(RedirectToPermissionDenied()); } if (id == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { var unitOfferingModel = UnitOfferingProcessor.SelectUnitOfferingForUnitOfferingId(id); if (unitOfferingModel == null) { return(RedirectToIndexIdNotFound(id)); } var unit = UnitProcessor.SelectUnitForUnitId(unitOfferingModel.UnitId); var teachingPeriod = TeachingPeriodProcessor.SelectTeachingPeriodForTeachingPeriodId(unitOfferingModel.TeachingPeriodId); var year = YearProcessor.SelectYearForYearId(unitOfferingModel.YearId); var convenor = UserProcessor.SelectUserForUserId(unitOfferingModel.ConvenorId); var projectOfferings = ProjectOfferingProcessor.SelectProjectOfferingsForUnitOfferingId(id); var enrollments = EnrollmentProcessor.LoadEnrollmentsForUnitOffering(id); // Convert the model data to non-model data // Pass the data to the view var unitOffering = new UnitOffering(unitOfferingModel, unit, teachingPeriod, year, convenor, projectOfferings, enrollments); ViewBag.UserId = new SelectList(unitOffering.GetStudents( ), "UserId", "Username", null); return(View(unitOffering)); } catch (Exception e) { return(RedirectToIndex(e)); } // Find Unit Offering //db.GetUnitOffering( id ); // Populate Student Drop Down List for to add new Enrollments //PopulateStudentDropDownList( ); // Navigate to View //return View( db ); }
public ActionResult Edit(TeachingPeriod teachingPeriod) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.TeachingPeriod)) { return(RedirectToPermissionDenied()); } if (ModelState.IsValid) { try { // Ensure Month and Day qualify as a valid date within a leap year if (!ValidDate(teachingPeriod.Month, teachingPeriod.Day)) { throw new DataException("Selected Date not valid."); } // Construct DataLayer Model var teachingPeriodModel = new TeachingPeriodModel( ); teachingPeriodModel.TeachingPeriodId = teachingPeriod.TeachingPeriodId; teachingPeriodModel.Name = teachingPeriod.Name; teachingPeriodModel.Month = teachingPeriod.Month; teachingPeriodModel.Day = teachingPeriod.Day; // Attempt to Edit TeachingPeriod TeachingPeriodProcessor.EditTeachingPeriod(teachingPeriodModel); // If successful return to Index return(RedirectToAction("Index")); } catch (Exception e) { // Show Valid Date Error or DataLayer Errors ModelState.AddModelError("", e.Message); } } else { // Show ModelState Errors var errors = ModelState.Values.SelectMany(v => v.Errors); } // Redirects to page where data is reloaded db.GetTeachingPeriod(teachingPeriod.TeachingPeriodId); return(View(db)); }
public TeachingPeriod GetTeachingPeriodForName(string name) { var data = TeachingPeriodProcessor.SelectTeachingPeriodForName(name); var teachingPeriod = new TeachingPeriod { TeachingPeriodId = data.TeachingPeriodId, Name = data.Name, Month = data.Month, Day = data.Day }; TeachingPeriod = teachingPeriod; return(TeachingPeriod); }
private void GetUnitOffering(int id) { var data = UnitOfferingProcessor.SelectUnitOfferingForUnitOfferingId(id); UnitOffering = new UnitOffering( ) { UnitOfferingId = data.UnitOfferingId, TeachingPeriodId = data.TeachingPeriodId, YearId = data.YearId, ConvenorId = data.ConvenorId, UnitId = data.UnitId, }; var teachingperiodData = TeachingPeriodProcessor.SelectTeachingPeriodForTeachingPeriodId(UnitOffering.TeachingPeriodId); UnitOffering.TeachingPeriod = new TeachingPeriod( ) { TeachingPeriodId = teachingperiodData.TeachingPeriodId, Name = teachingperiodData.Name, Day = teachingperiodData.Day, Month = teachingperiodData.Month }; var yearData = YearProcessor.SelectYearForYearId(UnitOffering.YearId); UnitOffering.Year = new Year( ) { YearId = yearData.YearId, YearValue = yearData.Year }; var convenorData = UserProcessor.SelectUserForUserId(UnitOffering.ConvenorId); UnitOffering.Convenor = new User( ) { UserId = convenorData.UserId, Username = convenorData.Username }; var unitData = UnitProcessor.SelectUnitForUnitId(UnitOffering.UnitId); UnitOffering.Unit = new Unit( ) { UnitId = unitData.UnitId, Name = unitData.Name }; }
public List <TeachingPeriod> GetTeachingPeriods( ) { var teachingPeriodData = TeachingPeriodProcessor.SelectTeachingPeriods( ); TeachingPeriods = new List <TeachingPeriod>( ); foreach (var row in teachingPeriodData) { var teachingPeriod = new TeachingPeriod( ) { TeachingPeriodId = row.TeachingPeriodId, Name = row.Name }; TeachingPeriods.Add(teachingPeriod); } return(TeachingPeriods); }
public ActionResult Create(TeachingPeriod model) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.TeachingPeriod)) { return(RedirectToPermissionDenied()); } if (ModelState.IsValid) { try { // Ensure Month and Day qualify as a valid date within a leap year if (!ValidDate(model.Month, model.Day)) { throw new DataException("Selected Date not valid."); } // Attempt to Insert TeachingPeriod TeachingPeriodProcessor.InsertTeachingPeriod(model.Name, model.Month, model.Day); // If Insert successful return to Index return(RedirectToAction("Index")); } catch (Exception e) { // Show Valid Date Error or DataLayer Errors var errors = ModelState.Values.SelectMany(v => v.Errors); } } else { // Show modelState errors var errors = ModelState.Values.SelectMany(v => v.Errors); } // Return to View return(View( )); }