Пример #1
0
        public async Task <User> CreateByEmail(Guid id, Guid guildId, String email, String password, String name, DateTime?dateOfBirth = null,
                                               GamerRank rank = GamerRank.Beginner, GamerStatus status = GamerStatus.New,
                                               CancellationToken cancellationToken = default)
        {
            var user = await _repository.Get(id, cancellationToken);

            if (user == null)
            {
                user = await _repository.GetUserByEmail(email, guildId, cancellationToken);
            }

            if (user != null)
            {
                if (user.Id == id &&
                    user.Email == email &&
                    user.Name == name &&
                    user.GuildId == guildId &&
                    (dateOfBirth == null || user.DateOfBirth == dateOfBirth))
                {
                    return(user);
                }
                throw new UserAlreadyExistsException();
            }

            user = new User(id, guildId, name, rank, status, dateOfBirth ?? DateTime.UtcNow, null, email);
            user.SetPassword(_passwordHasher.GetHash(user.Id, user.Email, password));
            return(user);
        }
Пример #2
0
 public void ChangeRank(GamerRank rank)
 {
     if (Rank == rank)
     {
         return;
     }
     Rank = rank;
     ConcurrencyTokens = Guid.NewGuid();
     UpdateDate        = DateTime.UtcNow;
 }
Пример #3
0
        public static void AddOrUpdateRole(this Guild guild, GamerRank rank, Decimal loanTax, Decimal expiredLoanTax, ICollection <Decimal> tax)
        {
            if (guild.Roles.Any(_ => _.UserRoleId == rank))
            {
                guild.DeleteRole(rank);
            }
            var roles = new UserRole(rank, new Tariff(loanTax, expiredLoanTax, tax.ToJson()));

            guild.AddNewRole(roles);
        }
Пример #4
0
        internal void DeleteRole(GamerRank rank)
        {
            if (Roles.All(_ => _.UserRoleId != rank))
            {
                throw new InvalidOperationException("Role not found");
            }

            Roles.Remove(Roles.Single(_ => _.UserRoleId == rank));
            ConcurrencyTokens = Guid.NewGuid();
        }
Пример #5
0
        public async Task <IActionResult> SetOrUpdateGuildTax(
            [FromBody] UpdateUserRoleBinding binding,
            [FromRoute] GamerRank rank,
            [FromServices] IGuildRepository guildRepository,
            CancellationToken cancellationToken)
        {
            var guild = await guildRepository.Get(HttpContext.GetGuildId(), cancellationToken);

            if (guild == null)
            {
                throw new ApiException(HttpStatusCode.NotFound, ErrorCodes.GuildNotFound, "Guild not found");
            }

            guild.AddOrUpdateRole(rank, binding.Tariff.LoanTax, binding.Tariff.ExpiredLoanTax, binding.Tariff.Tax);

            guildRepository.Save(guild);

            return(Ok(new { }));
        }
Пример #6
0
 public ProfileView(Guid userId, String name, GamerRank rank, String characterName, Int32 charCount, Decimal balance,
                    Decimal activeLoanAmount, Decimal activePenaltyAmount, Decimal activeLoanTaxAmount, DateTime dateOfBirth)
 => (UserId, Name, Rank, CharacterName, CharCount, Balance,
Пример #7
0
 public User(Guid id, Guid guildId, String?name, GamerRank rank, GamerStatus status, DateTime dateOfBirth, String?login, String?email)
 => (Id, GuildId, Name, Rank, Status, DateOfBirth, Login, Email)
Пример #8
0
 public GuildRoleView(Guid guildId, GamerRank userRoleId, Decimal loanTax, Decimal expiredLoanTax, ICollection <Decimal> tax)
 => (GuildId, UserRoleId, LoanTax, ExpiredLoanTax, Tax)
Пример #9
0
 public UserRole(GamerRank userRoleId, Tariff tariff)
 => (UserRoleId, Tariff)
Пример #10
0
 public User(Guid id, string login, GamerRank rank, Guid guildId, string roles, string name, GamerStatus status, DateTime createDate, DateTime updateDate, DateTime dateOfBirth)
 => (Id, Login, Rank, GuildId, Roles, Name, Status, CreateDate, UpdateDate, DateOfBirth)
Пример #11
0
 public GamersListView(Guid id, String name, Decimal balance,
                       IEnumerable <CharacterView> characters, GamerRank rank, GamerStatus status,
                       DateTime dateOfBirth, IEnumerable <PenaltyView> penalties, IEnumerable <LoanView> loans)
 => (Id, Name, Balance, Characters, Rank, Status, DateOfBirth, Penalties, Loans)
Пример #12
0
        public async Task <User> Create(Guid id, Guid guildId, String login, String name, DateTime dateOfBirth, GamerRank rank, GamerStatus status,
                                        CancellationToken cancellationToken)
        {
            var user = await _repository.Get(id, cancellationToken);

            if (user != null)
            {
                if (user.Login == login &&
                    user.Name == name &&
                    user.DateOfBirth == dateOfBirth)
                {
                    return(user);
                }
                throw new UserAlreadyExistsException();
            }

            return(new User(id, guildId, name, rank, status, dateOfBirth, login, null));
        }