public int RemoveTimeSlot(TimeSlot timeSlot) { int count = 0; try { DBConnection.OpenConnection(); SqlCommand cmd = new SqlCommand(CommonConstants.QUERY_REMOVE_TIMESLOT, DBConnection.DatabaseConnection); cmd.Parameters.AddWithValue(CommonConstants.PARAMETER_DAY_OF_THE_WEEK, timeSlot.GetDay_of_the_Week()); cmd.Parameters.AddWithValue(CommonConstants.PARAMETER_START_TIME, timeSlot.GetStart_Time()); cmd.Parameters.AddWithValue(CommonConstants.PARAMETER_END_TIME, timeSlot.GetEnd_Time()); cmd.Parameters.AddWithValue(CommonConstants.PARAMETER_TYPE, timeSlot.GetSlotType()); count = cmd.ExecuteNonQuery(); } catch (Exception ex) { try { Console.WriteLine(ex); DBConnection.CloseConnection(); } catch (Exception) { throw; } return(-1); } finally { try { DBConnection.CloseConnection(); } catch (Exception) { throw; } } return(count); }
public int SaveTimeSlot(TimeSlot timeSlots) { int count = 0; try { DBConnection.OpenConnection(); SqlCommand cmd2 = new SqlCommand(CommonConstants.QUERY_GET_TIMESLOT, DBConnection.DatabaseConnection); cmd2.Parameters.AddWithValue(CommonConstants.PARAMETER_DAY_OF_THE_WEEK, timeSlots.GetDay_of_the_Week()); cmd2.Parameters.AddWithValue(CommonConstants.PARAMETER_START_TIME, timeSlots.GetStart_Time()); cmd2.Parameters.AddWithValue(CommonConstants.PARAMETER_END_TIME, timeSlots.GetEnd_Time()); cmd2.Parameters.AddWithValue(CommonConstants.PARAMETER_TYPE, timeSlots.GetSlotType()); SqlDataReader reader = cmd2.ExecuteReader(); if (reader.Read()) { reader.Close(); DBConnection.CloseConnection(); return(0); } reader.Close(); DBConnection.CloseConnection(); if (timeSlots.GetSlotType().Trim() == "Lunch Break") { DBConnection.OpenConnection(); SqlCommand cmd3 = new SqlCommand(CommonConstants.QUERY_GET_LUNCH_BREAK_COUNT_FOR_THE_DAY, DBConnection.DatabaseConnection); cmd3.Parameters.AddWithValue(CommonConstants.PARAMETER_DAY_OF_THE_WEEK, timeSlots.GetDay_of_the_Week()); cmd3.Parameters.AddWithValue(CommonConstants.PARAMETER_TYPE, timeSlots.GetSlotType()); SqlDataReader reader2 = cmd3.ExecuteReader(); reader2.Read(); if (int.Parse(reader2[CommonConstants.COLUMN_BREAK_COUNT].ToString()) >= 1) { reader2.Close(); DBConnection.CloseConnection(); return(-2); } DBConnection.CloseConnection(); } DBConnection.OpenConnection(); SqlCommand cmd = new SqlCommand(CommonConstants.QUERY_SAVE_TIMESLOT, DBConnection.DatabaseConnection); cmd.Parameters.AddWithValue(CommonConstants.PARAMETER_DAY_OF_THE_WEEK, timeSlots.GetDay_of_the_Week()); cmd.Parameters.AddWithValue(CommonConstants.PARAMETER_START_TIME, timeSlots.GetStart_Time()); cmd.Parameters.AddWithValue(CommonConstants.PARAMETER_END_TIME, timeSlots.GetEnd_Time()); cmd.Parameters.AddWithValue(CommonConstants.PARAMETER_TYPE, timeSlots.GetSlotType()); count = cmd.ExecuteNonQuery(); } catch (Exception ex) { try { Console.WriteLine(ex); DBConnection.CloseConnection(); } catch (Exception) { throw; } return(-1); } finally { try { DBConnection.CloseConnection(); } catch (Exception) { throw; } } return(count); }