51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using Quartz;
|
|
using System.Threading.Tasks;
|
|
using Newtonsoft.Json;
|
|
using System.Text;
|
|
|
|
namespace birzha_contracts.Jobs{
|
|
[DisallowConcurrentExecution]
|
|
public class HelloWorldJob : IJob
|
|
{
|
|
|
|
private readonly ILogger<HelloWorldJob> _logger;
|
|
private readonly IServiceProvider _provider;
|
|
private static readonly HttpClient client = new HttpClient();
|
|
|
|
public HelloWorldJob(ILogger<HelloWorldJob> logger, IServiceProvider provider)
|
|
{
|
|
_logger = logger;
|
|
_provider = provider;
|
|
}
|
|
|
|
public Task Execute(IJobExecutionContext context)
|
|
{
|
|
using(var scope = _provider.CreateScope())
|
|
{
|
|
var dbContext = scope.ServiceProvider.GetService<MvcContractContext>();
|
|
|
|
var contracts = dbContext.Contract.Take(1).ToList();
|
|
|
|
var data = JsonConvert.SerializeObject(contracts);
|
|
|
|
var content = new StringContent(data.ToString(), Encoding.UTF8, "application/json");
|
|
|
|
client.BaseAddress = new Uri("http://ba.digital-tps.tk");
|
|
|
|
var request = new HttpRequestMessage(HttpMethod.Post, $"/api/contract/import");
|
|
|
|
request.Content = content;
|
|
|
|
var response = client.Send(request);
|
|
// fetch customers, send email, update DB
|
|
}
|
|
|
|
_logger.LogInformation("Success!");
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|
|
|
|
|