The problem as reported by the error message is:
"An error occurred when trying to create a controller of type 'BooksController'. Make sure that the controller has a parameterless public constructor."
I'm trying to have the controller successfully execute and/or return a value.
This is a WebApi project using an AngularJs app as the frontend. Any calls to this controller return a 500 error with the above message. Ishould also add that I am using Insight.Database
I have tried creating a new controller and adding and removing the constructor. But I wan't able to get any better hints about what I'm doing wrong.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Data.SqlClient;
using System.Configuration;
using System.Threading.Tasks;
using Insight.Database;
using Owin;
using Microsoft.Owin;
using Microsoft.Owin.Security.OAuth;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.SqlServer;
using Wallet.Models.Books;
using Wallet.Models.Stores;
using Wallet.Models.Database;
namespace Wallet.Controllers
{
[Authorize]
[RoutePrefix("api/books")]
public class BooksController : ApiController
{
private IBooksDataAccess access;
public BooksController()
{
access = HttpContext.Current.GetOwinContext().Get<SqlConnection>()
.As<IBooksDataAccess>();
}
// POST api/books/GetActions
[HttpPost]
[Route("GetActions")]
public IList<HistoryAction> ActionsHH([FromBody] Dictionary<string, string> input)
{
var name = input["name"];
var results = access.GetHistoricalActions(name);
return results;
}
// POST api/books/InsertTransaction
[HttpPost]
[Route("InsertTransaction")]
public void InsertTx([FromBody] Dictionary<string, string> input)
{
}
}
}
And here's the IBookDataAccess
namespace Wallet.Models.Database
{
[Sql(Schema = "Models")]
public interface IBooksDataAccess
{
IList<HistoryAction> GetHistoricalActions(string UserName);
int InsertTransaction(Dictionary<string, string> transaction);
}
}