Hi, i have two solutions
1. ASP.NET web application(.Net framework)(Web Api)
2. ASP.NET Core application(.Net Core)
in Visula Studio 17.
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions, RequestMethod } from '@angular/http';
import 'rxjs/Rx';
import { Employee } from '../models/Employee'
@Injectable()
export class EmployeeManagementService {
constructor(private http: Http) {
}
}
addEmployeeDetails(employeeDetails: Employee) {
var obj = {Firstname: employeeDetails.FirstName, LastName: employeeDetails.LastName, PhoneNumber: employeeDetails.PhoneNumber};
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' });
let options = new RequestOptions({ method: RequestMethod.Post, headers: headers });
let emp = JSON.stringify({ obj });
return this.http.post('http://localhost:xyz/api/employee-management/create-employee', emp, options)
.map((res: Response) => res.json())
.toPromise();
public class EmployeeManagementApiController : ApiController
{
[HttpPost]
[Route("api/employee-management/create-employee")]
public IHttpActionResult CreateEmployee([FromBody]Employee emp)
{
EmployeeService service = new EmployeeService();
var serv = service.CreateEmployee(emp);
if (serv.status == 1)
{
return Ok(emp);
}
else
return new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.PreconditionFailed, serv.message));
}
}
Employee.ts file
<pre>
public class Employee
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string PhoneNumber { get; set; }
}
<pre>
export class Employee {
FirstName: string;
LastName: string;
PhoneNumber: string;
}
My ts file is in on solution and my api is in another solution.
here am getting calls to my API but emp values are all null. Am i missing anything . Please help me out.
Thanks in advance
What I have tried:
same code i have tried with normal controller in same Solution ,
if i send single parameter values is passed to API controller.