Пример #1
0
        /// <summary>
        /// The update competition.
        /// </summary>
        /// <param name="competitionId">
        /// The competition Id.
        /// </param>
        /// <param name="station">
        /// The station.
        /// </param>
        /// <returns>
        /// The <see cref="Station"/>.
        /// </returns>
        public Station UpdateStation(Guid competitionId, Station station)
        {
            var competition = this.competitionRepository.FilterBy(x => x.Id.Equals(competitionId)).FirstOrDefault();

            if (competition == null)
            {
                throw new Exception("There are no competition with ID " + competitionId);
            }

            if (!this.RightsHelper.GetRightsForCompetitionIdAndTheUser(competitionId)
                .Contains(WinShooterCompetitionPermissions.UpdateStation))
            {
                this.log.ErrorFormat(
                    "User {0} does not have enough rights to read stations for competition {1}",
                    this.currentUser,
                    competitionId);
                throw new NotEnoughRightsException("You don't have rights to update stations for this competition");
            }

            var databaseStation =
                this.stationRepository.FilterBy(x => x.Competition.Id.Equals(competitionId) && x.Id.Equals(station.Id)).FirstOrDefault();

            if (databaseStation == null)
            {
                throw new Exception(string.Format("There is no station for competition {0} with Id {1}", competitionId, station.Id));
            }

            databaseStation.UpdateFromOther(station);

            using (var transaction = this.stationRepository.StartTransaction())
            {
                if (this.stationRepository.Update(databaseStation))
                {
                    transaction.Commit();
                }
            }

            return databaseStation;
        }
Пример #2
0
 /// <summary>
 /// Update these values from other station.
 /// </summary>
 /// <param name="other">
 /// The other.
 /// </param>
 public virtual void UpdateFromOther(Station other)
 {
     this.NumberOfShots = other.NumberOfShots;
     this.NumberOfTargets = other.NumberOfTargets;
     this.Points = other.Points;
     this.Distinguish = other.Distinguish;
     this.StationNumber = other.StationNumber;
 }
Пример #3
0
        /// <summary>
        /// The update competition.
        /// </summary>
        /// <param name="competitionId">
        /// The competition Id.
        /// </param>
        /// <param name="station">
        /// The station.
        /// </param>
        /// <returns>
        /// The <see cref="Station"/>.
        /// </returns>
        public Station AddStation(Guid competitionId, Station station)
        {
            var competition = this.competitionRepository.FilterBy(x => x.Id.Equals(competitionId)).FirstOrDefault();

            if (competition == null)
            {
                throw new Exception("There are no competition with ID " + competitionId);
            }

            if (!this.RightsHelper.GetRightsForCompetitionIdAndTheUser(competitionId)
                .Contains(WinShooterCompetitionPermissions.CreateStation))
            {
                this.log.ErrorFormat(
                    "User {0} does not have enough rights to read stations for competition {1}",
                    this.currentUser,
                    competitionId);
                throw new NotEnoughRightsException("You don't have rights to read stations for this competition");
            }

            var stationCount = this.stationRepository.FilterBy(x => x.Competition.Id.Equals(competitionId)).Count();

            station.Competition = competition;
            station.StationNumber = stationCount + 1;

            using (var transaction = this.stationRepository.StartTransaction())
            {
                if (this.stationRepository.Add(station))
                {
                    transaction.Commit();
                }
            }

            return station;
        }