コード例 #1
0
        public async Task <UserDto> Get(string subject)
        {
            var user = await Repository.Get(subject);

            if (user == null)
            {
                var now = DateTime.UtcNow;
                user = new User();
                user.SetName($"User{now.Hour}{now.Minute}{now.Second}{now.Millisecond}");
                user.AddCredential(subject);
                user.SetLastLogin();
                user.SetVerificationCode(_randomService.GenerateVerificationCode());
                if (await Repository.Create(user))
                {
                    PublishUserInfoChangedIntegrationEvent(user);
                }
            }
            else
            {
                user.SetLastLogin();
                if (!await Repository.Update(user))
                {
                    throw new Exception("Failed to update user");
                }
            }

            return(user.ToDto());
        }