Ramco Ramco

Ramco Ramco

  • 437
  • 3.4k
  • 541.9k

Post Api with few fields

Feb 25 2021 4:28 PM
Hi
  I have below Api but i want only 3 values ID,Name,DepartmentId to be passed in Body to this Api with Encrytion
How it can be done.
 
 
[HttpPost]
[ResponseType(typeof(Employee))]
public HttpResponseMessage PostEmployee([FromBody]Employee employee)
{
try
{
db.Employees.Add(employee);
db.SaveChanges();
var message = Request.CreateResponse(HttpStatusCode.Created, employee);
message.Headers.Location = new Uri(Request.RequestUri + employee.ID.ToString());
return message;
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
 
-------------------------------------
public partial class Employee
{
public int ID { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Gender { get; set; }
public Nullable<int> Salary { get; set; }
public Nullable<int> DepartmentId { get; set; }
public string Active { get; set; }
public Nullable<System.DateTime> CreatedOn { get; set; }
public Nullable<System.DateTime> UpdatedOn { get; set; }
//public Department Department { get; set; }
public virtual Department Department { get; set; }
}
 
 
Thanks 

Answers (3)