/// <summary> /// Updates a competition. /// </summary> /// <param name="competition"> /// The competition to add or update. /// </param> public void UpdateCompetition(Competition competition) { if ( !this.RightsHelper.GetRightsForCompetitionIdAndTheUser(competition.Id) .Contains(WinShooterCompetitionPermissions.UpdateCompetition)) { this.log.ErrorFormat( "User {0} does not have enough rights to update competition {1}", this.currentUser, competition); throw new NotEnoughRightsException("You don't have rights to update this competition"); } competition.VerifyDataContent(); var currentCompetition = this.competitionRepository.FilterBy(x => x.Id.Equals(competition.Id)).FirstOrDefault(); if (currentCompetition == null) { throw new Exception("There is no such competition to update."); } this.log.DebugFormat("Updating competition {0} with new values {1}", currentCompetition, competition); currentCompetition.UpdateFromOther(competition); using (var transaction = this.competitionRepository.StartTransaction()) { if (this.competitionRepository.Update(currentCompetition)) { this.log.Debug("Committing transaction."); transaction.Commit(); } } }
/// <summary> /// Adds a new competition. /// </summary> /// <param name="user"> /// The user trying to add or update a competition. /// </param> /// <param name="competition"> /// The competition to add or update. /// </param> /// <returns> /// The <see cref="Guid"/> of the new competition. /// </returns> public Competition AddCompetition(User user, Competition competition) { competition.Id = Guid.NewGuid(); competition.VerifyDataContent(); var rolesLogic = new RolesLogic(); var role = rolesLogic.DefaultOwnerRole; if (role == null) { // This should never happen throw new NullReferenceException(string.Format("Default Owner Role \"{0}\" is not present.", rolesLogic.DefaultOwnerRoleName)); } var userRolesInfo = new UserRolesInfo { Competition = competition, Role = role, User = user }; using (var transaction = this.competitionRepository.StartTransaction()) { // First add the new competition to database this.competitionRepository.Add(competition); // Then add the user as admin this.userRolesInfoRepository.Add(userRolesInfo); // Commit transaction transaction.Commit(); } return competition; }