Exemplo n.º 1
0
        public async Task <MemberSummaryResponse> AddMemberAsync(string saasUserId, string email)
        {
            var member = await UnitOfWork.MemberRepository.GetMemberBySaasUserIdAsync(saasUserId);

            if (member != null)
            {
                throw new NetKitChatInvalidOperationException($"Unable to add member. Member {nameof(saasUserId)}:{saasUserId} already exists.");
            }

            var newMember = new DomainModels.Member
            {
                Id           = Guid.NewGuid(),
                Role         = UserRole.User,
                IsBanned     = false,
                Status       = UserStatus.Online,
                SaasUserId   = saasUserId,
                Email        = email,
                LastActivity = _dateTimeProvider.GetUtcNow(),
                Name         = email
            };
            await UnitOfWork.MemberRepository.AddMemberAsync(newMember);

            return(DomainModelsMapper.MapToMemberSummaryResponse(newMember));
        }
Exemplo n.º 2
0
        public ChannelSummaryResponse MapToDirectChannelSummaryResponse(Channel channel, DomainModels.Member currentUser, DomainModels.Member directMember, Message lastReadMessage = null)
        {
            var response = new ChannelSummaryResponse();

            if (channel != null)
            {
                response = _mapper.Map(channel, response);
                var lastMessage = channel.Messages.OrderBy(o => o.Created).LastOrDefault();
                if (lastMessage != null)
                {
                    response.LastMessage = MapToMessageResponse(lastMessage, lastReadMessage?.Created);
                }
                response.UnreadMessagesCount = lastReadMessage != null?
                                               channel.Messages.Count(x => x.Created > lastReadMessage.Created) :
                                                   channel.Messages.Count;
            }

            if (currentUser != null)
            {
                response.CreatorId = currentUser.Id;
                response.Creator   = MapToMemberSummaryResponse(currentUser);
            }

            if (directMember != null)
            {
                response.DirectMemberId = directMember.Id;
                response.DirectMember   = MapToMemberSummaryResponse(directMember);
            }

            return(response);
        }
Exemplo n.º 3
0
 public MemberSummaryResponse MapToMemberSummaryResponse(DomainModels.Member member)
 {
     return(member != null?_mapper.Map <MemberSummaryResponse>(member) : new MemberSummaryResponse());
 }
Exemplo n.º 4
0
        public DirectChannelResponse MapToDirectChannelResponse(Guid directChannelId, DomainModels.Member owner, DomainModels.Member member)
        {
            var firstMember = owner != null?_mapper.Map <MemberSummaryResponse>(owner) : new MemberSummaryResponse();

            var secondMember = owner != null?_mapper.Map <MemberSummaryResponse>(member) : new MemberSummaryResponse();

            return(new DirectChannelResponse
            {
                DirectChannelId = directChannelId,
                Owner = firstMember,
                Member = secondMember
            });
        }