ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 277.8k

How to represent create new employee record by web API ?

Feb 15 2019 7:34 PM
Problem

How to represent create new employee record by web API ?
i work on project asp.net core 2.1

i create mvc controller employee controller and inside it i make create action result for create new employee view with
get type and show last record exist on database plus one as below :
 
  1. public IActionResult Create()  
  2. {  
  3. var model = new Employee();  
  4. if (id == null)  
  5. {  
  6.   
  7. model.EmployeeId = _repository.GetAll().Max(Employee => Employee.EmployeeId) + 1;  
  8.   
  9. }  
  10. return View(model);  
  11. }  
 

I need to convert action result create to web API to connect to angular
so that
How to convert function action result create to web API ?
so that i create new web API controller :
  1. [Produces("application/json")]  
  2. [Route("api/Employee")]  
  3. public class EmployeeController : Controller  
  4. {  
  5. //how to write code for create by using web api  
  6. }  
 

view source
print?

Answers (1)