public void AdjustMatchDeadlines(Board board) { foreach (var match in board.Matches.Where(match => !match.IsResolved)) { match.VerificationDeadline = match.Created.AddHours(board.AutoVerification); } }
public ActionResult Create(Board board) { if (ModelState.IsValid) { var owner = new Competitor { Name = User.Identity.Name, Rating = board.StartingRating, Profile = _repository.UserProfiles.FindProfile(User.Identity.Name) }; _repository.Add(owner); _repository.CommitChanges(); board.Created = DateTime.Now; board.Started = DateTime.Now; board.Owner = owner; board.Competitors.Add(owner); _repository.Add(board); _repository.CommitChanges(); return RedirectToAction("Index"); } return View(board); }
public BoardViewModel(Board board) { BoardId = board.BoardId; Name = board.Name; Owner = new CompetitorViewModel(board.Owner); Created = String.Format("{0:g}", board.Created); End = String.Format("{0:g}", board.End); PercentComplete = CalculatePercentComplete(board); }
public DiscussionViewModel(Board board, IPagedList<PostViewModel> posts, int focusPostId, Competitor viewer) { Board = board; FocusPostId = focusPostId; Viewer = viewer != null && viewer.Status == CompetitorStatus.Active ? new CompetitorViewModel(viewer) : new CompetitorViewModel(); Posts = posts; }
private static int CalculatePercentComplete(Board board) { if (board.Started == DateTime.MinValue) return (0); if (DateTime.Now >= board.End) return(100); var totalDays = (board.End - board.Started).TotalDays; var elapsedDays = totalDays - (board.End - DateTime.Now).TotalDays; return ((elapsedDays / totalDays * 100).RoundToWhole()); }
//public ActionResult Edit(int id, FormCollection formValues) public ActionResult Edit(int id, Board userBoard) { var board = _repository.GetBoardById(id); if (board == null) return View("BoardNotFound"); if (ModelState.IsValid) { if (!board.IsOwner(User.Identity.Name)) return View("InvalidOwner", board); if (userBoard.AutoVerification != board.AutoVerification) { userBoard.Matches = _repository.GetUnresolvedMatchesByBoardId(userBoard.BoardId).ToList(); _boardService.AdjustMatchDeadlines(userBoard); } TryUpdateModel(board); _repository.CommitChanges(true); TempData["StatusMessage"] = "Your changes have been saved."; return RedirectToAction("Details", new { id = userBoard.BoardId }); } return View(board); }
public void Delete(Board board) { _boards.Remove(board); }
public void Add(Board board) { _boards.Add(board); }
public void Add(Board board) { Db.Boards.Add(board); }
public static IRepository CreatePopulatedRepository() { var repository = new InMemoryRepository(); var competitorOwnerProfile = new UserProfile { UserId = 0, UserName = "******" }; var competitorProfile1 = new UserProfile { UserId = 1, UserName = "******" }; var competitorProfile2 = new UserProfile { UserId = 2, UserName = "******" }; var boardOwner = new Competitor { Name = competitorOwnerProfile.UserName, ProfileUserId = 0, Profile = competitorOwnerProfile, Rating = 1500, }; var competitor1 = new Competitor { Name = competitorProfile1.UserName, ProfileUserId = 1, Profile = competitorProfile1, Rating = 1500, }; var competitor2 = new Competitor { Name = competitorProfile2.UserName, ProfileUserId = 2, Profile = competitorProfile2, Rating = 1500, }; var board = new Board { BoardId = 1, AutoVerification = 1, Created = DateTime.Now, Description = "Test Board", End = DateTime.Now.AddDays(30), Name = "Test Board", Owner = boardOwner, Started = DateTime.Now, StartingRating = 1500, Competitors = new[] { boardOwner, competitor1, competitor2 } }; // Unresolved match var match1 = new Match { Board = board, Created = DateTime.Now, Loser = competitor2, Winner = competitor1, VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification), MatchId = 1, LoserRatingDelta = -10, WinnerRatingDelta = 10 }; // Unresolved match var match2 = new Match { Board = board, Created = DateTime.Now, Loser = competitor1, Winner = competitor2, VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification), MatchId = 2, LoserRatingDelta = -10, WinnerRatingDelta = 10 }; // Unresolved match var match3 = new Match { Board = board, Created = DateTime.Now, Loser = competitor2, Winner = competitor1, VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification), MatchId = 3, LoserRatingDelta = -10, WinnerRatingDelta = 10 }; // Resolved Match [Verified] var match4 = new Match { Board = board, Created = DateTime.Now.AddDays(-7), Loser = competitor1, Winner = competitor2, VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification), MatchId = 4, LoserRatingDelta = -10, WinnerRatingDelta = 10, Resolved = DateTime.Now.AddHours(board.AutoVerification), Verified = true }; // Resolved Match [Rejected] var match5 = new Match { Board = board, Created = DateTime.Now.AddDays(-7), Loser = competitor2, Winner = competitor1, VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification), MatchId = 4, LoserRatingDelta = -10, WinnerRatingDelta = 10, Resolved = DateTime.Now.AddHours(board.AutoVerification), Rejected = true }; board.Matches = new[] { match1, match2, match3 }; // Boards repository.Add(board); // User Profiles repository.Add(competitorOwnerProfile); repository.Add(competitorProfile1); repository.Add(competitorProfile2); // Competitors repository.Add(boardOwner); repository.Add(competitor1); repository.Add(competitor2); // Matches repository.Add(match1); repository.Add(match2); repository.Add(match3); repository.Add(match4); repository.Add(match5); return (repository); }
// Competitor public static bool CanEdit(this Competitor competitor, Board board, string name) { return (board.IsOwner(name) || competitor.Is(name)); }