} //List Method public int Update(CTRModal ctr) { int rowsAffected = 0; using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); SqlCommand command = new SqlCommand("spUpdateCTR", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Id", ctr.Id); command.Parameters.AddWithValue("@SessionId", ctr.SessionId); command.Parameters.AddWithValue("@SemesterId", ctr.SemesterId); command.Parameters.AddWithValue("@SectionId", ctr.SectionId); command.Parameters.AddWithValue("@CourseId", ctr.CourseId); command.Parameters.AddWithValue("@TeacherId", ctr.TeacherId); try { rowsAffected = command.ExecuteNonQuery(); } catch (Exception e) { return(0); } return(rowsAffected); } }
public int Insert(CTRModal ctr) { bool isDuplicate = CheckPrimaryKeyViolation(ctr.SessionId, ctr.SemesterId, ctr.SectionId, ctr.CourseId, ctr.TeacherId); if (isDuplicate) { return(0); } int noOfRowsAffected = 0; using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); SqlCommand command = new SqlCommand("spInsertCTR", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@SessionId", ctr.SessionId); command.Parameters.AddWithValue("@SemesterId", ctr.SemesterId); command.Parameters.AddWithValue("@SectionId", ctr.SectionId); command.Parameters.AddWithValue("@CourseId", ctr.CourseId); command.Parameters.AddWithValue("@TeacherId", ctr.TeacherId); try { noOfRowsAffected = command.ExecuteNonQuery(); } catch (SqlException ex) { if (ex.Number == 2627) { return(0); } } } return(noOfRowsAffected); } // Insert Method
public JsonResult Update(CTRModal ctrOject) { return(Json(_databaseConnection.Update(ctrOject), JsonRequestBehavior.AllowGet)); }
public JsonResult Insert(CTRModal ctr) { return(Json(_databaseConnection.Insert(ctr), JsonRequestBehavior.AllowGet)); }