Я оставлю код ниже:
Код: Выделить всё
[ApiController]
[Route("api/[controller]")]
public class Controller3 : ControllerBase
{
private readonly IServiceContract3 _interest;
public Controller3(IServiceContract3 interest)
{
_interest = interest;
}
[HttpGet]
[Route("[action]")]
[Route("api/Interest/GetInterests")]
public IEnumerable GetEmployees()
{
return _interest.GetInterests();
}
[HttpPost]
[Route("[action]")]
[Route("api/Interest/AddInterest")]
public IActionResult AddInterest(Interest interest)
{
_interest.AddInterest(interest);
return Ok();
}
[HttpPost]
[Route("[action]")]
[Route("api/Interest/UpdateInterest")]
public IActionResult UpdateInterest(Interest interest)
{
_interest.UpdateInterest(interest);
return Ok();
}
[HttpDelete]
[Route("[action]")]
[Route("api/Interest/DeleteInterest")]
public IActionResult DeleteInterest(int id)
{
var existingInterest = _interest.GetInterest(id);
if (existingInterest != null)
{
_interest.DeleteInterest(existingInterest.Id);
return Ok();
}
return NotFound($"Employee Not Found with ID : {existingInterest.Id}");
}
[HttpGet]
[Route("GetInterest")]
public Interest GetInterest(int id)
{
return _interest.GetInterest(id);
}
}
Код: Выделить всё
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddDbContextPool(options =>
options.UseSqlServer(Configuration.GetConnectionString("DB")));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DatabaseContext context)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
context.Database.Migrate();
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
Подробнее здесь: https://stackoverflow.com/questions/701 ... -attribute