public IHttpActionResult PostList(ListsModel list) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var addlist = new List(list); db.Lists.Add(addlist); db.SaveChanges(); list.ListID = addlist.ListID; list.CreatedDate = addlist.CreatedDate; return CreatedAtRoute("DefaultApi", new { id = list.ListID }, list); }
public IHttpActionResult PostList(ListModel list) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var dbList = new List(list); db.Lists.Add(dbList); db.SaveChanges(); list.CreatedDate = dbList.CreatedDate; list.ListId = dbList.ListId; // returns the object that is created return CreatedAtRoute("DefaultApi", new { id = dbList.ListId }, list); }
public IHttpActionResult PostList(ListModel list) { if (!ModelState.IsValid) { return BadRequest(ModelState); } //////////the New code var dblist = new List(list); //dblist.CreatedDate = DateTime.Now; list.CreatedDate = dblist.CreatedDate; //those tow lines to show the user the old values with updated dates. list.ListId = dblist.ListId; db.Lists.Add(dblist); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = list.ListId }, list); }