In the previous post, we have created a GET request with some code refactoring actions. In this post, we are going to create a POST, PUT and DELETE requests and by doing so we are going to complete the server part (.NET Core part) of this series. Let’s get into it. If you want to […].; Author: Code Maze; Updated: 19 Feb 2018; Section: Uncategorised Technical Blogs; Chapter: General Reading; Updated: 19 Feb 2018
In the previous post, we have created a GET request with some code refactoring actions. In this post, we are going to create a POST, PUT and DELETE requests and by doing so we are going to complete the server part (.NET Core part) of this series.
Let’s get into it.
If you want to see all the basic instructions and complete navigation for this series, please follow the following link: Introduction page for this tutorial.
For the previous part check out: Part 5 – Creating .NET Core WebApi project – Using repository for the GET requests
The source code is available for download at .NET Core, Angular 4 and MySQL. Part 6 – Source Code
This post is divided into several sections:
Firstly, let’s modify the decoration attribute for the action method GetOwnerById in the Owner controller:
[ HttpGet(” {id}”, Name = ” OwnerById”)]
With this modification, we are setting the name for the action. This name will come in handy in the action method for creating a new owner.
Secondly, let’s modify the interface:
public interface IOwnerRepository { IEnumerable GetAllOwners(); Owner GetOwnerById(Guid ownerId); OwnerExtended GetOwnerWithDetails(Guid ownerId); void CreateOwner(Owner owner); }
After the interface modification, we are going to implement that interface:
public void CreateOwner(Owner owner) { owner.Id = Guid.NewGuid(); Create(owner); Save(); }
Lastly, let’s modify the controller:
[ HttpPost] public IActionResult CreateOwner([FromBody]Owner owner) { try…
.NET Core 2.0, Angular 4 and MySQL. Part 6