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); }
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); }
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); }
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)); }
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); }