public ActionResult CreateSchedule(DrSchedule aSchedule) { aSchedule.DoctorId = (int)Session["Id"]; try { if (ModelState.IsValid) { if (aManager.IsDateExist(aSchedule)) { if (aManager.IsTimeExist(aSchedule)) { ViewBag.message = "schedule is conflicting"; } else { int message = aManager.ScheduleSave(aSchedule); if (message > 0) { ViewBag.message = "Schedule created successfully"; } else { ViewBag.message = "failed to create Schedule"; } } } else { int message = aManager.ScheduleSave(aSchedule); if (message > 0) { ViewBag.message = "Schedule created successfully"; } else { ViewBag.message = "failed to create Schedule"; } } } } catch (Exception exception) { ViewBag.message = exception.Message; } return(View()); }
public int ScheduleSave(DrSchedule aSchedule) { string query = @"INSERT INTO [dbo].[DrSchedule] ([DoctorId] ,[AppointmentDate] ,[StartTime] ,[EndTime]) VALUES('" + aSchedule.DoctorId + "','" + aSchedule.AppointmentDate + "','" + aSchedule.StartTime + "','" + aSchedule.EndTime + "')"; SqlCommand cmd = new SqlCommand(query, con); con.Open(); int rowAffected = cmd.ExecuteNonQuery(); return(rowAffected); }
public bool IsDateExist(DrSchedule aSchedule) { string query = @"SELECT * FROM [dbo].[DrSchedule] WHERE (Date <= @Date AND DoctorId = @DoctorId)"; SqlCommand cmd = new SqlCommand(query, con); con.Open(); cmd.Parameters.Clear(); cmd.Parameters.Add("Date", SqlDbType.Date); cmd.Parameters["Date"].Value = aSchedule.Date; cmd.Parameters.Add("DoctorId", SqlDbType.Int); cmd.Parameters["DoctorId"].Value = aSchedule.DoctorId; SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); bool isExist = reader.HasRows; reader.Close(); con.Close(); return(isExist); }
public bool IsTimeExist(DrSchedule aSchedule) { string query = @"SELECT * FROM [dbo].[DrSchedule] WHERE (StartTime <= @EndTime AND EndTime>=@StartTime AND DoctorId=@DoctorId)"; SqlCommand cmd = new SqlCommand(query, con); bool isExist = false; con.Open(); cmd.Parameters.Clear(); cmd.Parameters.Add("StartTime", SqlDbType.Char); cmd.Parameters["StartTime"].Value = aSchedule.StartTime; cmd.Parameters.Add("EndTime", SqlDbType.Char); cmd.Parameters["EndTime"].Value = aSchedule.EndTime; cmd.Parameters.Add("DoctorId", SqlDbType.Int); cmd.Parameters["DoctorId"].Value = aSchedule.DoctorId; SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); isExist = reader.HasRows; reader.Close(); con.Close(); return(isExist); }
public bool IsTimeExist(DrSchedule aSchedule) { string query = @"SELECT * FROM [dbo].[DrSchedule] WHERE ([Start-Time] <= @End_Time AND [End-Time]<=@Start_Time AND [DoctorId] = @DoctorId)"; SqlCommand cmd = new SqlCommand(); con.Open(); cmd.Parameters.Clear(); cmd.Parameters.Add("[Start-Time]", SqlDbType.Date); cmd.Parameters["[Start-Time]"].Value = aSchedule.Start_Time; cmd.Parameters.Add("[End-Time]", SqlDbType.Date); cmd.Parameters["[End-Time]"].Value = aSchedule.End_Time; cmd.Parameters.Add("[DoctorId]", SqlDbType.Int); cmd.Parameters["[DoctorId]"].Value = aSchedule.DoctorId; SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); bool isExist = reader.HasRows; reader.Close(); con.Close(); return(isExist); }
public bool IsTimeExist(DrSchedule aSchedule) { return(aGateway.IsTimeExist(aSchedule)); }
public int ScheduleSave(DrSchedule aSchedule) { return(aGateway.ScheduleSave(aSchedule)); }