public void InsertMidterm(MidTermModal midterm) { int rowsAffected = 0; using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); SqlCommand com = new SqlCommand("spInsertMidterm", connection); com.CommandType = CommandType.StoredProcedure; com.Parameters.AddWithValue("@SessionId", midterm.SessionId); com.Parameters.AddWithValue("@SemesterId", midterm.SemesterId); com.Parameters.AddWithValue("@CourseId", midterm.CourseId); com.Parameters.AddWithValue("@StartDay", midterm.StartDay); com.Parameters.AddWithValue("@StartMonth", midterm.StartMonth); com.Parameters.AddWithValue("@StartYear", midterm.StartYear); com.Parameters.AddWithValue("@Time", midterm.Time); try { rowsAffected = com.ExecuteNonQuery(); } catch (Exception exception) { } } }
public int Insert(MidTermModal midterm) { InsertMidterm(midterm); int midtermId = GetMidtermId(midterm.SessionId, midterm.SemesterId, midterm.CourseId); InsertSections(midterm.Sections, midtermId); return(1); }
public JsonResult Insert(MidTermModal midterm) { midterm.Sections = midterm.SectionNames.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); bool isExist = _databaseConnection.CheckDuplication(midterm); if (isExist) { return(Json('0', JsonRequestBehavior.AllowGet)); } return(Json(_databaseConnection.Insert(midterm))); }
public bool CheckDuplication(MidTermModal midterm) { List <MidTermModal> listOfMidTerm = new List <MidTermModal>(); using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); SqlCommand com = new SqlCommand("spListMidterm", connection); com.CommandType = CommandType.StoredProcedure; SqlDataReader rdr = com.ExecuteReader(); while (rdr.Read()) { listOfMidTerm.Add(new MidTermModal { Id = Int32.Parse(rdr["Id"].ToString()), SessionId = Int32.Parse(rdr["SessionId"].ToString()), SemesterId = Int32.Parse(rdr["SemesterId"].ToString()), CourseId = Int32.Parse(rdr["CourseId"].ToString()), StartDay = rdr["StartDay"].ToString(), StartMonth = rdr["StartMonth"].ToString(), StartYear = rdr["MaterialDescription"].ToString(), Time = rdr["Time"].ToString() }); } } foreach (MidTermModal midtermInDb in listOfMidTerm) { if ((midtermInDb.SessionId == midterm.SessionId && midtermInDb.SemesterId == midterm.SemesterId && midtermInDb.CourseId == midterm.CourseId)) { return(true); } } return(false); }