在ASP.NET Core 2.0中工作的控制器:
[Produces("application/json")]
[Route("api/[controller]")]
[ApiController]
public class GraficResourcesApiController : ControllerBase
{
private readonly ApplicationDbContext _context;
public GraficResourcesApiController(ApplicationDbContext context)
{
_context = context;
}
[HttpGet]
public JsonResult GetGrafic(int ResourceId)
{
var sheduling = new List<Sheduling>();
var events = from e in _context.Grafic.Where(c=>c.ResourceId == ResourceId)
select new
{
id = e.Id,
title = e.Personals.Name,
start = e.DateStart,
end = e.DateStop,
color = e.Personals.Color,
personalId = e.PersonalId,
description = e.ClientName
};
var rows = events.ToArray();
return Json(rows);
}
}
Run Code Online (Sandbox Code Playgroud)
在ASP.NET Core 2.1中 …
有三种型号:
承包商:
public class Contractor
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<ReportWork> ReportWorks { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
报告:
public class Report
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<ReportWork> ReportWorks { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
报告工作:
public class ReportWork
{
public int Id { get; set; }
public string ReportStatus { get; set; }
public int ReportId { get; set; …Run Code Online (Sandbox Code Playgroud) 如何在后台的计时器上写入数据库。例如,检查邮件并将新字母添加到数据库。在示例中,我在写入数据库之前简化了代码。
Microsoft示例中的类名称。录音课本身:
namespace EmailNews.Services
{
internal interface IScopedProcessingService
{
void DoWork();
}
internal class ScopedProcessingService : IScopedProcessingService
{
private readonly ApplicationDbContext _context;
public ScopedProcessingService(ApplicationDbContext context)
{
_context = context;
}
public void DoWork()
{
Mail mail = new Mail();
mail.Date = DateTime.Now;
mail.Note = "lala";
mail.Tema = "lala";
mail.Email = "lala";
_context.Add(mail);
_context.SaveChangesAsync();
}
}
}
Run Code Online (Sandbox Code Playgroud)
计时器类:
namespace EmailNews.Services
{
#region snippet1
internal class TimedHostedService : IHostedService, IDisposable
{
private readonly ILogger _logger;
private Timer _timer;
public TimedHostedService(IServiceProvider services, ILogger<TimedHostedService> …Run Code Online (Sandbox Code Playgroud) c# async-await asp.net-core asp.net-core-2.1 asp.net-core-hosted-services
c# ×3
json ×2
asp.net ×1
asp.net-core ×1
asp.net-core-hosted-services ×1
async-await ×1
jsonresult ×1