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)); }
public Subject(string name, SubjectType subjectType, double score, TeachingPeriod teachingPeriod, ushort year) { this.name = name; this.subjectType = subjectType; this.score = score; this.teachingPeriod = teachingPeriod; this.year = year; }
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 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( )); }