public async Task <Event> CreateEvent( Account account, AccountSet arbiterAccountSet, AccountSet participantsAccountSet, EventCondition eventCondition, EventRelationType eventRelationType, EventBetCondition eventBetCondition, string title, DateTime startDate, DateTime endDate) { using (this._scopeableFactory.Create()) { var @event = new Event { AccountId = account.Id, Title = title, StartDate = startDate == default(DateTime) ? DateTime.Now : startDate, EndDate = endDate, EventRelationTypeId = eventRelationType.Id, ArbiterAccountSetId = arbiterAccountSet.GetIdentifier(), ParticipantsAccountSetId = participantsAccountSet.GetIdentifier(), ExpectedEventConditionId = eventCondition.Id, EventBetConditionId = eventBetCondition.Id }; await this._repositoryEvent.Add(@event); return(@event); } }
private async Task Checks(Event @event, Account account, OutcomesType targetOutcomesType, EventBetCondition conditions, CurrencyType currencyType) { var ownerAccountId = @event.AccountId; if (conditions.CloseDate < DateTime.Now) { throw new InvalidOperationException("bet alrady closed"); } var accountSetId = @event.ArbiterAccountSetId; IEnumerable <AccountSetAccounts> arbiterAccounts = await this._repositoryAccountSetAccounts.GetFiltered(a => a.AccountSetId == accountSetId); if (arbiterAccounts.Any(a => a.AccountId == account.Id)) { throw new InvalidOperationException("you are arbiter of this bet"); } if (@event.ParticipantsAccountSetId != default(Guid)) { accountSetId = @event.ParticipantsAccountSetId; IEnumerable <AccountSetAccounts> participantsAccounts = await this._repositoryAccountSetAccounts.GetFiltered(a => a.AccountSetId == accountSetId); if (!participantsAccounts.Any(setitem => setitem.AccountId == account.Id) && account.Id != ownerAccountId) { throw new InvalidOperationException("Participants account has not you accountId"); } } var eventId = @event.Id; var accountId = account.Id; EventRelationType relationType = await this._repositoryEventRelationType.Get(@event.EventRelationTypeId); Bet bet = await this._repositoryBet.GetBy(b => b.EventId == eventId && b.AccountId == accountId); if (currencyType.Name == CurrencyType.Reputation && bet != null) { throw new InvalidOperationException("you already bet you reputation"); } if (relationType.Name != EventRelationType.MenyVsMeny) { eventId = @event.Id; Bet ownrbet = await this._repositoryBet.GetBy(b => b.EventId == eventId && b.AccountId == ownerAccountId); if (ownrbet == null) { if (ownerAccountId != account.Id) { throw new InvalidOperationException("cannot bet before owner in One vs Meny or One vs One relations"); } } else { if (ownrbet.OutcomesTypeId == targetOutcomesType.Id) { throw new InvalidOperationException("cannot bet same as owner in One vs Meny or One vs One relations"); } } if (relationType.Name == EventRelationType.OneVsOne) { eventId = @event.Id; IEnumerable <Bet> bets = await this._repositoryBet.GetFiltered(b => b.EventId == eventId); if (bets.Count() > 1) { throw new InvalidOperationException("alrady bet on all outcomes in One vs One relations"); } } } }