コード例 #1
0
            public async Task <Unit> Handle(DeleteCommand request, CancellationToken cancellationToken)
            {
                var fined = await _context.Contacts
                            .Where(contact => contact.ContactId == request.ContactId)
                            .FirstOrDefaultAsync(cancellationToken);

                _context.Contacts.Remove(fined);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
コード例 #2
0
            public async Task <Unit> Handle(CreateCommand request, CancellationToken cancellationToken)
            {
                await _context.Conversations.AddAsync(new Domain.API.Entities.Conversations
                {
                    LeftUserId  = request.LeftUser.UserId,
                    RightUserId = request.RightUser.UserId
                }, cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
コード例 #3
0
ファイル: CreateCommand.cs プロジェクト: liannoi/web-chat
            public async Task <int> Handle(CreateCommand request, CancellationToken cancellationToken)
            {
                var result = await _context.Contacts.AddAsync(new Domain.API.Entities.Contacts
                {
                    OwnerUserId = request.OwnerUserId,
                    Email       = request.Email,
                    Photo       = request.Photo,
                    FirstName   = request.FirstName,
                    LastName    = request.LastName
                }, cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);

                return(result.Entity.ContactId);
            }
コード例 #4
0
ファイル: UpdateCommand.cs プロジェクト: liannoi/web-chat
            public async Task <DetailsViewModel> Handle(UpdateCommand request, CancellationToken cancellationToken)
            {
                var fined = await _context.Contacts
                            .Where(contact => contact.ContactId == request.ContactId)
                            .FirstOrDefaultAsync(cancellationToken);

                fined.OwnerUserId = request.OwnerUserId;
                fined.FirstName   = request.FirstName;
                fined.LastName    = request.LastName;
                fined.Email       = request.Email;
                fined.Photo       = request.Photo;
                await _context.SaveChangesAsync(cancellationToken);

                return(_mapper.Map <DetailsViewModel>(fined));
            }
コード例 #5
0
ファイル: CreateCommand.cs プロジェクト: liannoi/web-chat
            public async Task <Unit> Handle(CreateCommand request, CancellationToken cancellationToken)
            {
                var conversation = new Domain.API.Entities.ConversationMessages
                {
                    ConversationId = request.Conversation.ConversationId,
                    Message        = request.Message,
                    Publish        = request.Publish,
                    OwnerUserId    = request.OwnerUserId
                };

                await _context.ConversationMessages.AddAsync(conversation, cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);

                await _mediator.Publish(new MessageCreated { MessageId = conversation.ConversationMessageId },
                                        cancellationToken);

                return(Unit.Value);
            }