public ActionResponse Allocate(RoomAllocation aRoomAllocation)
        {
            ActionResponse response = new ActionResponse();
            try
            {
                int compare = DateTime.Compare(aRoomAllocation.StartTime, aRoomAllocation.EndTime);
                if (compare > 0)
                {
                    response.Class = "danger";
                    response.Message = "End Time [" + aRoomAllocation.EndTime.ToString("hh:mm tt") + "] must be grater than Start Time [" + aRoomAllocation.StartTime.ToString("hh:mm tt") + "].";
                    return response;
                }
                bool isOverlap = aClassroomGateway.IsOverlap(aRoomAllocation);
                if (isOverlap)
                {
                    response.Class = "danger";
                    response.Message = "Overlapping problem: Another class is allocated with this schedule.";
                    return response;
                }

                aClassroomGateway.Allocate(aRoomAllocation);
                response.Class = "success";
                response.Message = "Room Allocated successfully.";
            }
            catch (SqlException ex)
            {
                response.Class = "warning";
                response.Message = ex.Message;
            }
            return response;
        }
        public void Allocate(RoomAllocation aRoomAllocation)
        {
            string query = "INSERT INTO RoomAllocation (RoomId, CourseId, DayId, StartTime, EndTime, IsCurrent) VALUES (@roomId, @courseId, @dayId, @startTime, @endTime, @isCurrent)";
            using (connection = new SqlConnection(connectionString))
            using (SqlCommand command = new SqlCommand(query, connection))
            {
                command.Parameters.Clear();
                command.Parameters.Add("roomId", sqlDbType: SqlDbType.Int);
                command.Parameters["roomId"].Value = aRoomAllocation.RoomId;

                command.Parameters.Add("courseId", sqlDbType: SqlDbType.Int);
                command.Parameters["courseId"].Value = aRoomAllocation.CourseId;

                command.Parameters.Add("dayId", sqlDbType: SqlDbType.Int);
                command.Parameters["dayId"].Value = aRoomAllocation.DayId;

                command.Parameters.Add("startTime", sqlDbType: SqlDbType.Time);
                command.Parameters["startTime"].Value = aRoomAllocation.StartTime.TimeOfDay;

                command.Parameters.Add("endTime", sqlDbType: SqlDbType.Time);
                command.Parameters["endTime"].Value = aRoomAllocation.EndTime.TimeOfDay;

                command.Parameters.Add("isCurrent", sqlDbType: SqlDbType.Bit);
                command.Parameters["isCurrent"].Value = aRoomAllocation.IsCurrent;

                connection.Open();
                command.ExecuteNonQuery();
            }
        }
 public ActionResult Allocate(RoomAllocation aRoomAllocation)
 {
     ViewBag.response = aClassroomManager.Allocate(aRoomAllocation);
     ViewBag.Departments = aDepartmentManager.GetAllDepartments();
     ViewBag.Days = aDayManager.GetAllDays();
     ViewBag.Rooms = aRoomManager.GetAllRooms();
     return View();
 }
        public bool IsOverlap(RoomAllocation aRoomAllocation)
        {
            string query = "SELECT * FROM RoomAllocation WHERE RoomId=@roomId AND DayId=@dayId AND ( ( StartTime > @startTime AND StartTime < @endTime ) OR ( EndTime > @startTime AND EndTime < @endTime ) ) AND IsCurrent=1";
            using (connection = new SqlConnection(connectionString))
            using (SqlCommand command = new SqlCommand(query, connection))
            {
                command.Parameters.Clear();
                command.Parameters.Add("roomId", sqlDbType: SqlDbType.Int);
                command.Parameters["roomId"].Value = aRoomAllocation.RoomId;

                command.Parameters.Add("dayId", sqlDbType: SqlDbType.Int);
                command.Parameters["dayId"].Value = aRoomAllocation.DayId;

                command.Parameters.Add("startTime", sqlDbType: SqlDbType.Time);
                command.Parameters["startTime"].Value = aRoomAllocation.StartTime.TimeOfDay;

                command.Parameters.Add("endTime", sqlDbType: SqlDbType.Time);
                command.Parameters["endTime"].Value = aRoomAllocation.EndTime.TimeOfDay;

                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                return reader.HasRows;
            }
        }