Exemplo n.º 1
0
        public async Task <DomainValidationResult <Invitation> > SendInvitationAsync(ClanId clanId, UserId userId, UserId ownerId)
        {
            var result = new DomainValidationResult <Invitation>();

            if (!await _clanRepository.IsOwnerAsync(clanId, ownerId))
            {
                result.AddDebugError("Permission required.");
            }

            if (await _clanRepository.IsMemberAsync(userId))
            {
                result.AddDebugError("Target already in a clan.");
            }

            if (await _invitationRepository.ExistsAsync(ownerId, clanId))
            {
                result.AddFailedPreconditionError("The invitation from this clan to that member already exist.");
            }

            if (result.IsValid)
            {
                var invitation = new Invitation(userId, clanId);

                _invitationRepository.Create(invitation);

                await _invitationRepository.UnitOfWork.CommitAsync();

                return(invitation);
            }

            return(result);
        }