void Start() { for (int i = 0; i < buildingCreates.Count; i++) { if (buildingCreates[i].unitSize.Length == 0) { //set building features BuildingProcessor building = new BuildingProcessor(); building.setBlock(buildingCreates[i].block); building.setHeight(buildingCreates[i].height); building.setName(buildingCreates[i].nameOfBuilding); building.setWeight(buildingCreates[i].weight); buildings.Add(building); } else { //set Unitbuilding features UnitProcessor unit = new UnitProcessor(); unit.setBlock(buildingCreates[i].block); unit.setHeight(buildingCreates[i].height); unit.setName(buildingCreates[i].nameOfBuilding); unit.setWeight(buildingCreates[i].weight); unit.setUnitSize(buildingCreates[i].unitSize); units.Add(unit); } } }
/// <summary> /// The main page of the unit controller /// Shows a list of all units 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.Unit)) { return(RedirectToPermissionDenied()); } // Set the page message ViewBag.Message = "Units List"; // Get all units from the database var unitModels = UnitProcessor.SelectUnits( ); // Change the format of the year list List <Unit> units = new List <Unit>( ); foreach (var u in unitModels) { units.Add(new Unit(u)); } // Return the view, with the list of years return(View(units)); }
/// <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 Unit GetUnitForName(string name) { var data = UnitProcessor.SelectUnitForName(name); var unit = new Unit { UnitId = data.UnitId, Name = data.Name }; Unit = unit; return(Unit); }
public Unit GetUnit(int id) { var data = UnitProcessor.SelectUnitForUnitId(id); var unit = new Unit { UnitId = data.UnitId, Name = data.Name }; Unit = unit; return(Unit); }
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 <Unit> GetUnits( ) { var unitData = UnitProcessor.SelectUnits( ); Units = new List <Unit>( ); foreach (var row in unitData) { var unit = new Unit( ) { UnitId = row.UnitId, Name = row.Name }; Units.Add(unit); } return(Units); }
public ActionResult Edit(Unit unit) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.Unit)) { return(RedirectToPermissionDenied()); } if (ModelState.IsValid) { try { // Construct DataLayer Model var unitModel = new UnitModel( ); unitModel.UnitId = unit.UnitId; unitModel.Name = unit.Name; // Attempt to Edit Unit UnitProcessor.EditUnit(unitModel); // If Edit successful return to Index return(RedirectToAction("Index")); } catch (Exception e) { // Show 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.GetUnit(unit.UnitId); return(View(db)); }
public ActionResult Create(Unit model) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.Unit)) { return(RedirectToPermissionDenied()); } if (ModelState.IsValid) { try { // Attempt to Insert new Unit UnitProcessor.InsertUnit(model.Name); // If Insert successful return to Index return(RedirectToAction("Index")); } catch (Exception e) { // Show 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( )); }
public ActionResult Delete(Unit unit) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.Unit)) { return(RedirectToPermissionDenied()); } try { // Ensure no UnitOfferings are using this Unit before attempting delete. if (UnitOfferingProcessor.SelectUnitOfferingCountForUnit(unit.UnitId) > 0) { throw new DataException("Unable to delete Unit. One or more Unit Offerings require it."); } // Attempt to Delete Unit UnitProcessor.DeleteUnit(unit.UnitId); // 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.GetUnit(unit.UnitId); return(View(db)); }