Exemplo n.º 1
0
        public static ClientView Create(Domain.Client.Client o)
        {
            var v = new ClientView();

            if (!(o?.Data is null))
            {
                Copy.Members(o.Data, v);
            }
            return(v);
        }
Exemplo n.º 2
0
        public static ClientResponse ToClientResponse(this Domain.Client.Client client, string saasUserId)
        {
            var clientResponse = new ClientResponse();

            if (client != null)
            {
                clientResponse.Id = client.Id;
                clientResponse.ConnectionClientId = client.ClientConnectionId;
                clientResponse.SaasUserId         = saasUserId;
                clientResponse.UserName           = client.Name;
            }
            return(clientResponse);
        }
Exemplo n.º 3
0
        // TODO:Add unit test
        public async Task <ClientResponse> GetOrAddClientAsync(AddClientRequest request)
        {
            var member = await UnitOfWork.MemberRepository.GetMemberBySaasUserIdAsync(request.SaasUserId);

            if (member == null)
            {
                var newMember = new Domain.Member.Member
                {
                    Id           = Guid.NewGuid(),
                    Role         = UserRole.User,
                    IsAfk        = false,
                    IsBanned     = false,
                    Status       = UserStatus.Active,
                    Name         = request.UserName,
                    LastActivity = DateTimeOffset.UtcNow,
                    SaasUserId   = request.SaasUserId
                };
                await UnitOfWork.MemberRepository.AddMemberAsync(newMember);
            }

            member = await UnitOfWork.MemberRepository.GetMemberBySaasUserIdAsync(request.SaasUserId);

            var client = await UnitOfWork.ClientRepository.GetClientByConnectionIdAsync(request.ConnectionId);

            if (client != null)
            {
                return(client.ToClientResponse(member.SaasUserId));
            }

            client = new Domain.Client.Client
            {
                Id                 = Guid.NewGuid(),
                MemberId           = member.Id,
                ClientConnectionId = request.ConnectionId,
                LastActivity       = member.LastActivity,
                LastClientActivity = DateTimeOffset.UtcNow,
                Name               = request.UserName,
                UserAgent          = request.UserAgent
            };

            await UnitOfWork.ClientRepository.AddClientAsync(client);

            return(client.ToClientResponse(member.SaasUserId));
        }