public String Save(ClassRoom room) { if (room.StartTime > room.Endtime) { return "Time is Unvaluable.. Try Agein..!"; } bool isTimeScheduleValid = IsTimeScheduleValid(room.RoomId, room.DayId, room.StartTime, room.Endtime); if (isTimeScheduleValid != true) { if (classRoomGateway.Insert(room) > 0) { return "Saved Sucessfully!"; } return "Failed to save"; } return "Overlapping not allowed"; }
public ActionResult Save(ClassRoom classRoom) { try { string message = classRoomManager.Save(classRoom); // TODO: Add insert logic here ViewBag.Message = message; List<Day> days = dayManager.GetAllDays.ToList(); ViewBag.Days = days; List<Room> rooms = roomManager.GetAllRooms.ToList(); ViewBag.Rooms = rooms; var rr= departmentManager.GetAll(); ViewBag.Departments = rr; ViewBag.Courses = courseManager.GetAll; return View(); //return RedirectToAction("Index"); } catch { return View(); } }
public int Insert(ClassRoom room) { try { string query = "INSERT INTO t_AllocateClassRoom VALUES(@deptId,@courseId,@roomId,@dayId,@StartTime,@endTime,@allocationStatus)"; CommandObj.CommandText = query; CommandObj.Parameters.Clear(); CommandObj.Parameters.AddWithValue("@deptId", room.DepartmentId); CommandObj.Parameters.AddWithValue("@courseId", room.CourseId); CommandObj.Parameters.AddWithValue("@roomId", room.RoomId); CommandObj.Parameters.AddWithValue("@dayId", room.DayId); CommandObj.Parameters.AddWithValue("@startTime", room.StartTime.ToShortTimeString()); CommandObj.Parameters.AddWithValue("@endTime", room.Endtime.ToShortTimeString()); CommandObj.Parameters.AddWithValue("@allocationStatus", 1); ConnectionObj.Open(); int rowAffected = CommandObj.ExecuteNonQuery(); return rowAffected; } catch (Exception exception) { throw new Exception("Could not saved",exception); } finally { CommandObj.Dispose(); ConnectionObj.Close(); } }
public List<ClassRoom> GetClassSchedulByStartAndEndingTime(int roomId, int dayId, DateTime startTime, DateTime endTime) { try { //CommandObj.CommandText = "Select * from t_AllocateClassRoom where StartTime BETWEEN CAST('" + startTime +"' As Time) AND CAST('" + endTime + "' As Time) AND RoomId ='" + roomId + // "' AND DayId='" + dayId + "'"; CommandObj.CommandText = "Select * from t_AllocateClassRoom Where DayId=" + dayId + " AND RoomId="+roomId+" AND AllocationStatus=" + 1; List<ClassRoom> tempClassSchedules = new List<ClassRoom>(); ConnectionObj.Open(); SqlDataReader reader = CommandObj.ExecuteReader(); while (reader.Read()) { ClassRoom temp = new ClassRoom { Id = Convert.ToInt32(reader["Id"].ToString()), DepartmentId = Convert.ToInt32(reader["DepartmentId"].ToString()), CourseId = Convert.ToInt32(reader["CourseId"].ToString()), RoomId = Convert.ToInt32(reader["RoomId"].ToString()), DayId = Convert.ToInt32(reader["DayId"].ToString()), StartTime = Convert.ToDateTime(reader["StartTime"].ToString()), Endtime = Convert.ToDateTime(reader["EndTime"].ToString()) }; tempClassSchedules.Add(temp); } reader.Close(); return tempClassSchedules; } catch (Exception exception) { throw new Exception("Unable to collect class schedule", exception); } finally { CommandObj.Dispose(); ConnectionObj.Close(); } }