public bool FinalizeContest(int id, string userId) { var contest = this.Data.Contests.Find(id); if (contest == null) { throw new NotFoundException(string.Format("Contest with id {0} not found", id)); } if (contest.Status != ContestStatus.Active) { throw new BadRequestException(string.Format("Contest with id {0} is not active", id)); } var loggedUser = this.Data.Users.Find(userId); if (contest.OrganizatorId != loggedUser.Id) { throw new UnauthorizedException("Only the contest organizator can finalize it."); } contest.IsOpenForSubmissions = false; contest.Status = ContestStatus.Finalized; contest.EndDate = DateTime.Now; this.Data.SaveChanges(); var rewardStrategy = StrategyFactory.GetRewardStrategy(contest.RewardStrategy.RewardStrategyType); rewardStrategy.ApplyReward(this.Data, contest); return(true); }