// POST api/values public HttpResponseMessage Post([FromBody] clsStudents _students) { try { if (_students == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid input.")); } else { int rowsAffected = dbConnection.Execute(@"INSERT TBL_STUDENTS(Firstname,LastName,MobileNo) values (@FN, @LN, @MobileNo)", new { FN = _students.FirstName, LN = _students.LastName, MobileNo = _students.MobileNo }); if (rowsAffected > 0) { return(Request.CreateResponse(HttpStatusCode.Created, "Values are created.")); } else { return(Request.CreateResponse(HttpStatusCode.NotImplemented, "Values are created.")); } } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Error in Create:" + ex.Message)); } }
// PUT api/values/5 public HttpResponseMessage Put(long id, [FromBody] clsStudents _students) { try { if (_students == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid input.")); } else { int rowsAffected = dbConnection.Execute(@"Update TBL_STUDENTS set FirstName=@FN, LastName=@LN, MobileNo=@MBN where RID= " + id, new { FN = _students.FirstName, LN = _students.LastName, MBN = _students.MobileNo }); if (rowsAffected > 0) { return(Request.CreateResponse(HttpStatusCode.OK, "Values are updates.")); } else { return(Request.CreateResponse(HttpStatusCode.NotModified, "Values are not Modified.")); } } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Error in Update:" + ex.Message)); } }
// GET api/values/5 public HttpResponseMessage Get(long id) { try { clsStudents _getByStudents = dbConnection.Query <clsStudents>("select RID,Firstname, Lastname, MobileNo FROM TBL_STUDENTS WITH(NOLOCK) WHERE RID =" + id).SingleOrDefault(); return(Request.CreateResponse(HttpStatusCode.OK, _getByStudents)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Error in delete:" + ex.Message)); } }