public class ContactEmailModelĪll of the above compiles and seems to run fine, but will not provide a response. For example here is the email address model. Note that the query contains three includes and each of the included classes contain a navigation property back to the main contact. GET: api/valuesįirst get function returns all contacts and the second returns a specific contact based on the contact’s ID. Note that the context is being automatically injected via the constructor thanks to the fact that ASP.NET 5 now comes with dependency injection out of the box. The constructor takes the DbContext needed to access contacts. private readonly ContactsDbContext _dbContext For example the above route handles api/contacts. The route attribute is how the routing engine determines where to send requests. Using tells the routing engine to use the class name minus the word controller. The first thing to notice is the route attribute on the class declaration. The above code contains a lot of new concepts I am going to break it down more. Var contacts = from c in _dbContext.ContactModels Where(c => c.Id = id).FirstOrDefaultAsync() Return await GetContacts().ToListAsync() Public ContactsController(ContactsDbContext dbContext) Private readonly ContactsDbContext _dbContext Public class ContactsController : Controller Next I added a contacts controller to the API folder by right clicking on the folder and selecting add new item.įrom the add new item under DNX selected Web API Controller Class, entered a name and clicked add.įrom the resulting code I removed all the actions except for two get functions. To start with I added an API folder to my project to hold my API controller. I am going to create basic web API access to the contacts data I have been using in previous posts. If you have a suggestion on a better way to handle dates coming from JSON please leave a comment.Īlso note that there is an issue logged on the Angular repo to support strings in the built in date pipe which can be found here. The above are two of the solutions I came up with when I had problems with Angular’s built in date pipe. To have created just display the month, date and year the date pipe will be used with the short date format. Some common pipes are provided out of the box for things like numbers, dates and percentages.įor the following example created is a property for the date a contact was added. In Angular 2 pipes are away to apply some transformation on a field before its value is displayed to the user. The dates that needed to be formatted before being shown to the user which lead me to pipes. I am working on a project that is using an ASP.NET Core web API to return JSON that is then used by Angular 2.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |