ASP Net API pass parameter frombody

The action method:
1. Parameter as string
public HttpResponseMessage AddText(string jobNo,[FromBody] string text)
 {  .... }

test action:


2. Parameter as Custom Object

public class AddScheduleNote
    {
        public string JobNo { get; set; }
        public string ScheduleNote { get; set; }
    }

 ...................
public HttpResponseMessage UpdateScheduleNote([FromBody] AddScheduleNote note)
        {

            try
            {
                JobSchedule job = db.JobSchedules.Where(r => r.Job_No.Equals(note.JobNo, StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
                if (job == null)
                {
                    return Request.CreateResponse(HttpStatusCode.NoContent);
                }
                job.AddScheduleNode = note.ScheduleNote;
                db.SaveChanges();
                return Request.CreateResponse(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

        }





Comments

Popular posts from this blog

Setting IIS for https and domain

Make a website as a sub folder of an existed website in IIS