public async Task <bool> Callback(string type, string message) { if (type == "history") { HistoryMessage historyMessage = JsonConvert.DeserializeObject <HistoryMessage>(message); await AddHistory(historyMessage); return(true); } return(false); }
public async Task AddHistory(HistoryMessage historyMessage) { await Task.Run(async() => { using (var scope = _serviceScopeFactory.CreateScope()) { var serviceProvider = scope.ServiceProvider; var historyRepository = (IHistoryRepository)serviceProvider.GetService(typeof(IHistoryRepository)); var userService = (IUserService)serviceProvider.GetService(typeof(IUserService)); await AddHistoryToRepository(historyMessage, historyRepository, userService); } }); }
public async Task AddHistoryToRepository(HistoryMessage historyMessage, IHistoryRepository historyRepository, IUserService userService) { var authorUser = await userService.GetById(historyMessage.Author); var output = await GetDiff( historyRepository, historyMessage.Type, historyMessage.Id, historyMessage.Data); if (output != null) { var history = new History(authorUser.Email, historyMessage.Type, historyMessage.Id, output); if (_validation.Validate(history)) { await historyRepository.SaveAsync(history); } } }