public void Serialize() { var dbcompetition = new Competition { Id = Guid.Parse("74ec4f92-4b72-4c40-927a-de308269e074"), CompetitionType = CompetitionType.Field, IsPublic = true, Name = "Name", StartDate = DateTime.Parse("2014-01-31 21:41:00"), UseNorwegianCount = true }; var response = new CompetitionResponse(dbcompetition); Assert.AreEqual( "{\"CompetitionId\":\"74ec4f92-4b72-4c40-927a-de308269e074\",\"CompetitionType\":\"Field\",\"IsPublic\":true,\"Name\":\"Name\",\"StartDate\":\"2014-01-31T20:41:00.000Z\",\"UseNorwegianCount\":true}", JsonSerializer.SerializeToString(response)); }
/// <summary> /// Get a database competition. /// </summary> /// <returns> /// The <see cref="CompetitionRequest"/>. /// </returns> public Competition GetDatabaseCompetition() { var competitionType = (CompetitionType)Enum.Parse(typeof(CompetitionType), this.CompetitionType); var competitionId = string.IsNullOrEmpty(this.CompetitionId) ? Guid.Empty : Guid.Parse(this.CompetitionId); var toReturn = new Competition { CompetitionType = competitionType, Id = competitionId, IsPublic = this.IsPublic, Name = this.Name, StartDate = this.ParseStartDate(), UseNorwegianCount = this.UseNorwegianCount }; return toReturn; }
/// <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; }
/// <summary> /// Updates information from other competition. /// </summary> /// <param name="other"> /// The other. /// </param> public virtual void UpdateFromOther(Competition other) { this.Name = other.Name; this.StartDate = other.StartDate; this.CompetitionType = other.CompetitionType; this.UseNorwegianCount = other.UseNorwegianCount; this.IsPublic = other.IsPublic; }
/// <summary> /// Renumbers the stations in a competition. /// </summary> /// <param name="competition"> /// The competition. /// </param> private void RenumberStations(Competition competition) { // TODO: Implement }