public ActionResult Delete(Team team) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.Team)) { return(RedirectToPermissionDenied()); } try { int rowsDeleted = TeamProcessor.DeleteTeam(team.TeamId); if (rowsDeleted <= 0) { throw new DataException("Unable to Delete Team."); } return(RedirectToAction("Details", new RouteValueDictionary( new { controller = "ProjectOffering", action = "Details", Id = team.ProjectOfferingId }))); } catch (Exception e) { // Show any errors ModelState.AddModelError("", e.Message); } //Find Team var teamModel = TeamProcessor.GetTeamForTeamId(team.TeamId); var projectOffering = ProjectOfferingProcessor.SelectProjectOfferingForProjectOfferingId(teamModel.ProjectofferingId); return(View(new Team(teamModel, projectOffering))); }
public void Test_construction_with_mixed_null_parameters_throws_null_exception(IReader reader, INotify notify) { // Arrange. // Act. // Assert. Assert.Throws <ArgumentNullException>(() => _teamProcessor = new TeamProcessor(reader, notify)); }
public ActionResult AddTeamMember(Enrollment _Enrollment) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.Team)) { return(RedirectToPermissionDenied()); } if (_Enrollment.TeamId <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { // Ensure a User has been selected //if( _Enrollment.UserId <= 0 ) // throw new DataException( "No Enrolled User Selected." ); var enrollmentData = EnrollmentProcessor.SelectEnrollmentForEnrollmentId(_Enrollment.EnrollmentId); //Check if Student is already a member of this team var rowsFound = EnrollmentProcessor.SelectEnrollmentCountForTeamIdAndUserId(_Enrollment.TeamId, enrollmentData.UserId); if (rowsFound > 0) { throw new DataException($"User is already a member of this Team."); } // Attempt to update enrollment with TeamId EnrollmentProcessor.UpdateEnrollmentWithTeamId(enrollmentData.EnrollmentId, _Enrollment.TeamId); return(Redirect(Request.UrlReferrer.ToString( ))); } catch (Exception _Ex) { // Show Model Errors reload data and return to view. ModelState.AddModelError("", $"Unable to save changes due to Error: {_Ex.Message}"); } // Get the team data var teamModel = TeamProcessor.GetTeamForTeamId(_Enrollment.TeamId); if (teamModel == null) { return(RedirectToUnitOfferingIndex( )); } var projectOffering = ProjectOfferingProcessor.SelectProjectOfferingForProjectOfferingId(teamModel.ProjectofferingId); var team = new Team(teamModel, projectOffering); ViewBag.EnrollmentId = new SelectList(team.GetAvailableEnrollments(team.ProjectOfferingId), "EnrollmentId", "Username", null); return(View(team)); }
public FfdbEngine( IAppLogger logger, IServiceProvider serviceProvider, IDatabaseProvider databaseProvider, LatestWeekValue latestWeekValue, IWebRequestClient webRequestClient) { _serviceProvider = serviceProvider; _databaseProvider = databaseProvider; _latestWeekValue = latestWeekValue; _webRequestClient = webRequestClient; Stats = new StatsProcessor(serviceProvider); Team = new TeamProcessor(serviceProvider); Player = new PlayerProcessor(serviceProvider); }
public ActionResult Delete(ProjectOffering projectOffering) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.ProjectOffering)) { return(RedirectToPermissionDenied()); } try { if (db.GetProjectOffering(projectOffering.ProjectOfferingId) == null) { throw new DataException("This Project Offering does not exist."); } var existingTeams = TeamProcessor.SelectTeamsForProjectOfferingId(projectOffering.ProjectOfferingId); foreach (var team in existingTeams) { TeamProcessor.DeleteTeam(team.TeamId); } int rowsDeleted = ProjectOfferingProcessor.DeleteProjectOffering(projectOffering.ProjectOfferingId); if (rowsDeleted <= 0) { throw new DataException("Unable to Delete ProjectOffering."); } // If delete successful return to Index return(RedirectToAction("Index")); } catch (Exception e) { // Show any errors ModelState.AddModelError("", e.Message); } // If unsuccessful return to View return(View(db)); }
public ActionResult Details(int?id) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.ProjectOffering)) { return(RedirectToPermissionDenied()); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { int projectOfferingId = ( int )id; var projectOfferingModel = ProjectOfferingProcessor.SelectProjectOfferingForProjectOfferingId(projectOfferingId); if (projectOfferingModel == null) { return(RedirectToIndexIdNotFound(projectOfferingId)); } var project = ProjectProcessor.GetProject(projectOfferingModel.ProjectId); var unitOffering = UnitOfferingProcessor.SelectUnitOfferingForUnitOfferingId(projectOfferingModel.UnitOfferingId); var teams = TeamProcessor.SelectTeamsForProjectOfferingId(projectOfferingModel.ProjectOfferingId); var projectOffering = new ProjectOffering(projectOfferingModel, project, unitOffering, teams); return(View(projectOffering)); } catch (Exception e) { return(RedirectToIndex(e)); } }
public ActionResult Edit(Team team) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.Team)) { return(RedirectToPermissionDenied()); } if (ModelState.IsValid) { try { var teamModel = new TCABS_DataLibrary.Models.TeamModel( ); teamModel.TeamId = team.TeamId; teamModel.SupervisorId = team.SupervisorId; teamModel.Name = team.Name; TeamProcessor.EditTeam(teamModel); return(RedirectToAction("Details", new RouteValueDictionary( new { controller = "ProjectOffering", action = "Details", Id = team.ProjectOfferingId }))); } catch (Exception e) { // Show DataLayer errors ModelState.AddModelError("", e.Message); } } else { // Show ModelState Errors var errors = ModelState.Values.SelectMany(v => v.Errors); } return(View(team)); }
// Edit public ActionResult Edit(int?id) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.Team)) { return(RedirectToPermissionDenied()); } if (id == null) { //If no id supplied return error code return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } int teamId = ( int )id; //Attempt to Get team for Id var teamModel = TeamProcessor.GetTeamForTeamId(teamId); if (teamModel == null) { return(RedirectToUnitOfferingIndex( )); } var projectOffering = ProjectOfferingProcessor.SelectProjectOfferingForProjectOfferingId(teamModel.ProjectofferingId); //var project = ProjectProcessor.GetProject( teamModel.UnitOfferingId ); var team = new Team(teamModel, projectOffering); ViewBag.SupervisorId = new SelectList(team.GetAvailableSupervisors( ), "UserId", "Username", null); return(View(team)); }
// Details public ActionResult Details(int?id) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.Team)) { return(RedirectToPermissionDenied()); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { int teamId = ( int )id; // Get the team data var teamModel = TeamProcessor.GetTeamForTeamId(teamId); if (teamModel == null) { return(RedirectToUnitOfferingIndex( )); } var projectOffering = ProjectOfferingProcessor.SelectProjectOfferingForProjectOfferingId(teamModel.ProjectofferingId); var team = new Team(teamModel, projectOffering); ViewBag.EnrollmentId = new SelectList(team.GetAvailableEnrollments(team.ProjectOfferingId), "EnrollmentId", "Username", null); return(View(team)); } catch (Exception e) { return(RedirectToIndex(e)); } }
static void Main(string[] args) { Console.WriteLine("Hello."); var reader = new FileReader(new FileSystem()); var football = new FootballNotifier(); var processor = new TeamProcessor(reader, football); Console.WriteLine($"Processing the file '{AppConstants.FullFileName}'."); try { var result = processor.GetTeamWithLeastPointDifference(AppConstants.FullFileName); Console.WriteLine($"The result is: {result}."); } catch (Exception exception) { Console.WriteLine($"The application threw the following exception: {exception.Message}."); } Console.WriteLine("I hoped you enjoyed it!"); }
public ActionResult Create(Team model) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.Team)) { return(RedirectToPermissionDenied()); } if (ModelState.IsValid) { try { // Attempt to Insert new Team TeamProcessor.InsertTeam(model.SupervisorId, model.ProjectOfferingId, model.Name); // If Insert succesful return to Project //return RedirectToAction( "Details", "UnitOffering", model.UnitOfferingId ); return(RedirectToAction("Details", new RouteValueDictionary( new { controller = "ProjectOffering", action = "Details", Id = model.ProjectOfferingId }))); } catch (Exception e) { // Show DataLayer errors ModelState.AddModelError("", e.Message); } } else { // Show ModelState errors var errors = ModelState.Values.SelectMany(v => v.Errors); } return(View(model)); }
public ActionResult Delete(int?id) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.Team)) { return(RedirectToPermissionDenied()); } if (id == null) { // If no id provided show BadRequest Error return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } int teamId = ( int )id; // Get the team data var teamModel = TeamProcessor.GetTeamForTeamId(teamId); if (teamModel == null) { return(RedirectToUnitOfferingIndex( )); } var projectOffering = ProjectOfferingProcessor.SelectProjectOfferingForProjectOfferingId(teamModel.ProjectofferingId); //var project = ProjectProcessor.GetProject( teamModel.UnitOfferingId ); //var enrollments = EnrollmentProcessor.LoadEnrollmentsForTeam( id ); return(View(new Team(teamModel, projectOffering))); }
public TeamProcessorTests() { _reader = Substitute.For <IReader>(); _notify = Substitute.For <INotify>(); _teamProcessor = new TeamProcessor(_reader, _notify); }