public async Task <IHttpActionResult> PostctblReceiver([FromBody] ctblReceiver ctblReceiver) { cStatusStr status = new cStatusStr(); string retvalue; try { string constr = ConfigurationManager.ConnectionStrings["MyAbDbContext"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { SqlCommand cmd = new SqlCommand("sp_new_receiver", con); cmd.CommandType = CommandType.StoredProcedure; SqlParameter paramRecName = new SqlParameter(); paramRecName.ParameterName = "@ReceiverName"; paramRecName.Value = ctblReceiver.ReceiverName; cmd.Parameters.Add(paramRecName); SqlParameter paramRecPhone = new SqlParameter(); paramRecPhone.ParameterName = "@ReceiverPhone"; paramRecPhone.Value = ctblReceiver.ReceiverPhone; cmd.Parameters.Add(paramRecPhone); if (ctblReceiver.deviceTokenID == null) { ctblReceiver.deviceTokenID = "Assigned by API"; } SqlParameter paramRecdeviceTokenID = new SqlParameter(); paramRecdeviceTokenID.ParameterName = "@IME"; paramRecdeviceTokenID.Value = ctblReceiver.deviceTokenID; cmd.Parameters.Add(paramRecdeviceTokenID); SqlParameter paramRecSIMNO = new SqlParameter(); paramRecSIMNO.ParameterName = "@SIMNO"; paramRecSIMNO.Value = ctblReceiver.SIMNO; cmd.Parameters.Add(paramRecSIMNO); SqlParameter paramPOSTCODE = new SqlParameter(); paramPOSTCODE.ParameterName = "@POSTCODE"; paramPOSTCODE.Value = ctblReceiver.POSTCODE; cmd.Parameters.Add(paramPOSTCODE); cmd.Parameters.Add("@LastInsertedID", SqlDbType.Int); cmd.Parameters["@LastInsertedID"].Direction = ParameterDirection.Output; con.Open(); cmd.ExecuteNonQuery(); con.Close(); retvalue = cmd.Parameters["@LastInsertedID"].Value.ToString(); status.returnID = retvalue; //status.returnID = int.Parse(retvalue); if (status.returnID.Equals("-5")) //(status.returnID==-5) { status.StatusID = "1"; status.DesctoDev = "Restricted LISTENER NAME "; status.StatusMsg = " Restricted LISTENER NAME "; } if (status.returnID.Equals("-2")) //(status.returnID==-2) { status.StatusID = "1"; status.DesctoDev = "-2 is the error code for invalid POSTAL code. "; status.StatusMsg = " Invalid POSTAL Code. "; } if (int.Parse(status.returnID) >= 100000) /// (status.returnID >=100000) { status.StatusID = "0"; status.DesctoDev = "Store the returnID in Users Mobile database with UserType = R"; status.StatusMsg = " Listener Successfully Created/Updated "; status.userType = "R"; } } } catch (Exception ex) { status.StatusMsg = ex.Message.ToString(); status.StatusID = "1"; } return(Ok(status)); }
public IHttpActionResult PutctblReceiver([FromBody] ctblReceiver ctblReceiver) { string retvalue; cStatus status = new cStatus(); try { string constr = ConfigurationManager.ConnectionStrings["MyAbDbContext"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { SqlCommand cmd = new SqlCommand("sp_update_receiver", con); cmd.CommandType = CommandType.StoredProcedure; SqlParameter paramReceiverID = new SqlParameter(); paramReceiverID.ParameterName = "@ReceiverID"; paramReceiverID.Value = ctblReceiver.ReceiverID; cmd.Parameters.Add(paramReceiverID); SqlParameter paramRecName = new SqlParameter(); paramRecName.ParameterName = "@ReceiverName"; paramRecName.Value = ctblReceiver.ReceiverName; cmd.Parameters.Add(paramRecName); SqlParameter paramRecPhone = new SqlParameter(); paramRecPhone.ParameterName = "@ReceiverPhone"; paramRecPhone.Value = ctblReceiver.ReceiverPhone; cmd.Parameters.Add(paramRecPhone); SqlParameter paramAddress = new SqlParameter(); paramAddress.ParameterName = "@Address"; paramAddress.Value = ctblReceiver.Address; cmd.Parameters.Add(paramAddress); SqlParameter paramPOSTCODE = new SqlParameter(); paramPOSTCODE.ParameterName = "@POSTCODE"; paramPOSTCODE.Value = ctblReceiver.POSTCODE; cmd.Parameters.Add(paramPOSTCODE); SqlParameter paramActiveUser = new SqlParameter(); paramActiveUser.ParameterName = "@ActiveUser"; paramActiveUser.Value = ctblReceiver.ActiveUser; cmd.Parameters.Add(paramActiveUser); cmd.Parameters.Add("@LastupdatedID", SqlDbType.Int); cmd.Parameters["@LastupdatedID"].Direction = ParameterDirection.Output; con.Open(); cmd.ExecuteNonQuery(); con.Close(); retvalue = cmd.Parameters["@LastupdatedID"].Value.ToString(); status.returnID = int.Parse(retvalue); if (status.returnID == -2) { status.StatusID = 1; status.DesctoDev = "-2 is the error code for invalid POSTAL code. "; status.StatusMsg = " Invalid POSTAL Code. "; } if (status.returnID >= 100000) { status.StatusID = 0; status.DesctoDev = "Store the returnID in Users Mobile database with UserType = R"; status.StatusMsg = " Listener Successfully Created/Updated "; } } } catch (Exception ex) { retvalue = ex.Message.ToString(); } return(Ok(status)); }