public WorkHours GetWorkHoursByDay(string day) { WorkHours workHours = new WorkHours(); try { workHours.SetDay_of_the_Week(day); DBConnection.OpenConnection(); SqlCommand cmd = new SqlCommand(CommonConstants.QUERY_GET_START_AND_END_TIME_BY_DAY, DBConnection.DatabaseConnection); cmd.Parameters.AddWithValue(CommonConstants.PARAMETER_DAY_OF_THE_WEEK, workHours.GetDay_of_the_Week()); SqlDataReader myReader = cmd.ExecuteReader(); while (myReader.Read()) { workHours.SetStart_Time(myReader[CommonConstants.COLUMN_START_TIME].ToString()); workHours.SetEnd_Time(myReader[CommonConstants.COLUMN_END_TIME].ToString()); } myReader.Close(); } catch (Exception ex) { try { Console.WriteLine(ex); DBConnection.CloseConnection(); } catch (Exception) { throw; } } finally { try { DBConnection.CloseConnection(); } catch (Exception) { throw; } } return(workHours); }
public int SaveWorkingHours(WorkHours day) { int count = 0; try { DBConnection.OpenConnection(); SqlCommand cmd = new SqlCommand(CommonConstants.QUERY_SAVE_WORK_HOURS, DBConnection.DatabaseConnection); SqlCommand cmd2 = new SqlCommand(CommonConstants.QUERY_REMOVE_TIMESLOTS_BY_DAY, DBConnection.DatabaseConnection); cmd.Parameters.AddWithValue(CommonConstants.PARAMETER_START_TIME, day.GetStart_Time()); cmd.Parameters.AddWithValue(CommonConstants.PARAMETER_END_TIME, day.GetEnd_Time()); cmd.Parameters.AddWithValue(CommonConstants.PARAMETER_DAY_OF_THE_WEEK, day.GetDay_of_the_Week()); cmd2.Parameters.AddWithValue(CommonConstants.PARAMETER_DAY_OF_THE_WEEK, day.GetDay_of_the_Week()); count = cmd.ExecuteNonQuery(); int count2 = cmd2.ExecuteNonQuery(); if (count2 == -1 || count == -1) { count = -1; } } catch (Exception ex) { try { Console.WriteLine(ex); DBConnection.CloseConnection(); } catch (Exception) { throw; } return(-1); } finally { try { DBConnection.CloseConnection(); } catch (Exception) { throw; } } return(count); }