public async Task <SendMessageServiceResult> SendMessage(
            string senderUserId,
            string recieverUserId,
            string text)
        {
            var result = new SendMessageServiceResult();

            try
            {
                Message message = new Message()
                {
                    SenderId   = senderUserId,
                    RecieverId = recieverUserId,
                    Text       = text
                };
                _dbContext.Messages.Add(message);
                await _dbContext.SaveChangesAsync();

                result.Message = message;
            }
            catch (Exception ex)
            {
                result.AddError(ex.GetBaseException().ToString(), ex.ToString());
                await _loggerService.AddLogEntry(ex.GetBaseException().ToString(), ex.ToString());
            }

            return(result);
        }
Пример #2
0
        public async Task <BlockUserServiceResult> BlockUser(string sourceUserId, string targetUserId)
        {
            var result = new BlockUserServiceResult();

            try
            {
                UserBlock userBlock = new UserBlock()
                {
                    BlockerId = sourceUserId,
                    BlockedId = targetUserId
                };

                _dbContext.UserBlocks.Add(userBlock);
                await _dbContext.SaveChangesAsync();

                result.UserBlock = userBlock;
                await _loggerService.AddUserActivity(sourceUserId, EventConstants.BlockUser, $"User blocked user {targetUserId}");
            }
            catch (Exception ex)
            {
                result.AddError(ex.GetBaseException().ToString(), ex.ToString());
                await _loggerService.AddLogEntry(ex.GetBaseException().ToString(), ex.ToString());
            }

            return(result);
        }