public ActionResult AllocateClassRoom(ClassRoomAllocation aClassRoom)
 {
     ViewBag.Message       = aRoomManager.Save(aClassRoom);
     ViewBag.AllDepartment = aDepartmentManager.GetAllDepartment();
     ViewBag.AllClassRoom  = aDepartmentManager.GetAllClassRoom();
     return(View());
 }
        public JsonResult SaveRoomSchedule(ClassRoomAllocation classRoomAllocation)
        {
            var scheduleList = db.ClassRoomAllocations.Where(m => m.RoomId == classRoomAllocation.RoomId && m.DayId == classRoomAllocation.DayId && m.RoomStatus == "Allocated").ToList();

            if (scheduleList.Count == 0)
            {
                classRoomAllocation.RoomStatus = "Allocated";
                db.ClassRoomAllocations.Add(classRoomAllocation);
                db.SaveChanges();
                return(Json(true));
            }
            else
            {
                bool status = false;
                foreach (var allocation in scheduleList)
                {
                    if ((classRoomAllocation.StartTime >= allocation.StartTime && classRoomAllocation.StartTime < allocation.EndTime) ||
                        (classRoomAllocation.EndTime > allocation.StartTime && classRoomAllocation.EndTime <= allocation.EndTime) && classRoomAllocation.RoomStatus == "Allocated")
                    {
                        status = true;
                    }
                }
                if (status == false)
                {
                    classRoomAllocation.RoomStatus = "Allocated";
                    db.ClassRoomAllocations.Add(classRoomAllocation);
                    db.SaveChanges();
                    return(Json(true));
                }
                else
                {
                    return(Json(false));
                }
            }
        }
        public ActionResult Create([Bind(Include = "AllocationId,DepartmentId,CourseId,RoomId,Day,StartTime,EndTime")] ClassRoomAllocation classRoomAllocation)
        {
            if (ModelState.IsValid)
            {
                if (AllocateClassRoom(classRoomAllocation))
                {
                    classRoomAllocation.IsAllocated = true;
                    db.ClassRoomAllocations.Add(classRoomAllocation);
                    db.SaveChanges();
                    ModelState.Clear();

                    TempData["message"] = " ClassRoom Successfully Allocated";


                    //return RedirectToAction("Index");
                }
                else
                {
                    ViewBag.Allocation = "Allocation is not possible";
                }
            }

            ViewBag.CourseId     = new SelectList("", "Select....");
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "DepartmentName");
            ViewBag.RoomId       = new SelectList(db.Rooms, "RoomId", "RoomNo");
            return(View());
        }
        internal bool isexist(ClassRoomAllocation aClassRoom)
        {
            connection.ConnectionString = connectionString;

            //string query = "SELECT DepartmentCode FROM Department WHERE DepartmentCode='" + p + "'";
            string     query   = "SELECT * FROM AllocatedRoom WHERE RoomId = @RoomId and Day = @Day and Fromtime=@Fromtime";
            SqlCommand command = new SqlCommand(query, connection);

            command.Parameters.AddWithValue("RoomId", aClassRoom.RoomId);
            command.Parameters.AddWithValue("Day", aClassRoom.Day);
            command.Parameters.AddWithValue("Fromtime", aClassRoom.Fromtime);


            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                connection.Close();
                return(true);
            }
            else
            {
                connection.Close();
                return(false);
            }
        }
예제 #5
0
        public string Save(ClassRoomAllocation aClassRoom)
        {
            if (aClassRoom.Fromtime >= aClassRoom.Totime)
            {
                return("End Time Must Be Grater Than Start Time!");
            }
            else
            {
                bool isTimeScheduleValid = IsTimeScheduleValid(aClassRoom.RoomId, aClassRoom.DayId, aClassRoom.Fromtime, aClassRoom.Totime);

                if (isTimeScheduleValid != true)
                {
                    if (classRoomGateway.Save(aClassRoom) > 0)
                    {
                        return("Class Allocated Sucessfully!");
                    }
                    else
                    {
                        return("Class Allocation Failed... Please Try Again");
                    }
                }
                else
                {
                    return("Class Overlapping Is Invalid");
                }
            }
        }
        public List <ClassRoomAllocation> GetClassSchedulByStartAndEndingTime(int roomId, int dayId, DateTime startTime,
                                                                              DateTime endTime)
        {
            string query = "Select * from AllocateClassRoom Where DayId=" + dayId + " AND RoomId=" + roomId +
                           " AND AllocateStatus='Allocated'";
            List <ClassRoomAllocation> tempClassSchedules = new List <ClassRoomAllocation>();

            Command = new SqlCommand(query, Connection);
            Connection.Open();
            SqlDataReader Reader = Reader = Command.ExecuteReader();

            while (Reader.Read())
            {
                ClassRoomAllocation temp = new ClassRoomAllocation
                {
                    //AllocatedRoomId = 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()),
                    Fromtime     = Convert.ToDateTime(Reader["FromTime"].ToString()),
                    Totime       = Convert.ToDateTime(Reader["ToTime"].ToString())
                };
                tempClassSchedules.Add(temp);
            }
            Reader.Close();
            Connection.Close();
            return(tempClassSchedules);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ClassRoomAllocation classroomallocation = db.ClassRoomAllocations.Find(id);

            db.ClassRoomAllocations.Remove(classroomallocation);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        private void LoadDropDownList(ClassRoomAllocation classRoomAllocation)
        {
            var courses = db.Courses.Where(s => s.DepartmentId == classRoomAllocation.DepartmentId);

            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Code", classRoomAllocation.DepartmentId);
            ViewBag.CourseId     = new SelectList(courses.ToArray(), "CourseId", "Code", classRoomAllocation.CourseId);
            ViewBag.ClassRoomId  = new SelectList(db.ClassRooms, "ClassRoomId", "RoomNo", classRoomAllocation.ClassRoomId);
            ViewBag.DayId        = new SelectList(db.Days, "DayId", "Name", classRoomAllocation.DayId);
        }
        //
        // GET: /RoomAllocation/Delete/5

        public ActionResult Delete(int id = 0)
        {
            ClassRoomAllocation classroomallocation = db.ClassRoomAllocations.Find(id);

            if (classroomallocation == null)
            {
                return(HttpNotFound());
            }
            return(View(classroomallocation));
        }
예제 #10
0
        public string Save(ClassRoomAllocation allocation)
        {
            DateTime from = Convert.ToDateTime(allocation.FromTime);
            DateTime to   = Convert.ToDateTime(allocation.ToTime);


            List <ClassRoomAllocation> classRoom = classRoomAllocationGateway.IsTimeScheduleAllocated(allocation);

            if (classRoom.Count > 0)
            {
                foreach (ClassRoomAllocation allocate in classRoom)
                {
                    DateTime fromTime = Convert.ToDateTime(allocate.FromTime);
                    DateTime toTime   = Convert.ToDateTime(allocate.ToTime);
                    string   status   = allocate.Status;
                    if (from >= fromTime && from < toTime)
                    {
                        return("Room already allocated");
                    }
                    else if (to > fromTime && to <= toTime)
                    {
                        return("Room already allocated");
                    }
                    else if (from <= fromTime && to >= toTime)
                    {
                        return("Room already allocated");
                    }
                    else
                    {
                        int rowAffect = classRoomAllocationGateway.Save(allocation);
                        if (rowAffect > 0)
                        {
                            return("Room Allocated successfully");
                        }
                        else
                        {
                            return("Room Allocation failed");
                        }
                    }
                }
                return("Room Allocated successfully");
            }
            else
            {
                int rowAffect = classRoomAllocationGateway.Save(allocation);
                if (rowAffect > 0)
                {
                    return("Room Allocated successfully");
                }
                else
                {
                    return("Room Allocation failed");
                }
            }
        }
 public ActionResult Index(ClassRoomAllocation classRoomAllocation)
 {
     ViewBag.Departments          = new TeacherController().GetDepartmentForDropDown();
     ViewBag.ClassRooms           = GetClassRoomForDropDown();
     ViewBag.Days                 = GetDayForDropDown();
     classRoomAllocation.TimeFrom = classRoomAllocation.TimeFrom.Remove(2, 1);
     classRoomAllocation.TimeTo   = classRoomAllocation.TimeTo.Remove(2, 1);
     ViewBag.Message              = new ClassRoomManager().AllocateNewClassRoom(classRoomAllocation);
     ModelState.Clear();
     return(View());
 }
예제 #12
0
        public int AllocateNewClassRoom(ClassRoomAllocation classRoomAllocation)
        {
            string query = "INSERT INTO ClassRoomAllocationTable Values('" + classRoomAllocation.TimeFrom + "','" + classRoomAllocation.TimeTo + "','0','" + classRoomAllocation.DepartmentId + "','" + classRoomAllocation.CourseId + "','" + classRoomAllocation.RoomNoId + "','" + classRoomAllocation.SevenDayWeekId + "')";

            _command = new SqlCommand(query, _connection);
            _connection.Open();
            int rowAffect = _command.ExecuteNonQuery();

            _connection.Close();
            return(rowAffect);
        }
예제 #13
0
 public string AllocateNewClassRoom(ClassRoomAllocation classRoomAllocation)
 {
     if (!_classRoomGateway.IsAllocationPossible(classRoomAllocation))
     {
         return("Cannot Possible");
     }
     else
     {
         int rowAffected = _classRoomGateway.AllocateNewClassRoom(classRoomAllocation);
         return(rowAffected > 0 ? "Class Room Allocated Successfully" : "Failed");
     }
 }
 public ActionResult Edit([Bind(Include = "AllocationId,DepartmentId,CourseId,RoomId,Day,StartTime,EndTime")] ClassRoomAllocation classRoomAllocation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(classRoomAllocation).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CourseId     = new SelectList(db.Courses, "CourseId", "CourseCode", classRoomAllocation.CourseId);
     ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "DepartmentName", classRoomAllocation.DepartmentId);
     ViewBag.RoomId       = new SelectList(db.Rooms, "RoomId", "RoomNo", classRoomAllocation.RoomId);
     return(View(classRoomAllocation));
 }
        // GET: ClassRoomAllocation/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ClassRoomAllocation classRoomAllocation = db.ClassRoomAllocations.Find(id);

            if (classRoomAllocation == null)
            {
                return(HttpNotFound());
            }
            return(View(classRoomAllocation));
        }
        //
        // GET: /RoomAllocation/Edit/5

        public ActionResult Edit(int id = 0)
        {
            ClassRoomAllocation classroomallocation = db.ClassRoomAllocations.Find(id);

            if (classroomallocation == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Code", classroomallocation.DepartmentId);
            ViewBag.CourseId     = new SelectList(db.Courses, "CourseId", "Code", classroomallocation.CourseId);
            ViewBag.ClassRoomId  = new SelectList(db.ClassRooms, "ClassRoomId", "RoomNo", classroomallocation.ClassRoomId);
            ViewBag.DayId        = new SelectList(db.Days, "DayId", "Name", classroomallocation.DayId);
            return(View(classroomallocation));
        }
 public ActionResult Edit([Bind(Include = "Id,DepartmentId,CourseId,RoomId,TimeId,StartDate,EndDate")] ClassRoomAllocation classRoomAllocation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(classRoomAllocation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CourseId     = new SelectList(db.Courses, "Id", "Course_Code", classRoomAllocation.CourseId);
     ViewBag.DepartmentId = new SelectList(db.Deparments, "Id", "DeptCode", classRoomAllocation.DepartmentId);
     ViewBag.RoomId       = new SelectList(db.Rooms, "Id", "Name", classRoomAllocation.RoomId);
     ViewBag.TimeId       = new SelectList(db.Times, "Id", "Name", classRoomAllocation.TimeId);
     return(View(classRoomAllocation));
 }
 public ActionResult Edit(ClassRoomAllocation classroomallocation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(classroomallocation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Code", classroomallocation.DepartmentId);
     ViewBag.CourseId     = new SelectList(db.Courses, "CourseId", "Code", classroomallocation.CourseId);
     ViewBag.ClassRoomId  = new SelectList(db.ClassRooms, "ClassRoomId", "RoomNo", classroomallocation.ClassRoomId);
     ViewBag.DayId        = new SelectList(db.Days, "DayId", "Name", classroomallocation.DayId);
     return(View(classroomallocation));
 }
        public ActionResult Create([Bind(Include = "Id,DepartmentId,CourseId,RoomId,DayId,StartTime,EndTime,RoomStatus")] ClassRoomAllocation classroomallocation)
        {
            if (ModelState.IsValid)
            {
                db.ClassRoomAllocations.Add(classroomallocation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CourseId     = new SelectList(db.Courses, "Id", "CourseCode", classroomallocation.CourseId);
            ViewBag.DayId        = new SelectList(db.Days, "Id", "Name", classroomallocation.DayId);
            ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "DeptCode", classroomallocation.DepartmentId);
            ViewBag.RoomId       = new SelectList(db.Rooms, "Id", "Name", classroomallocation.RoomId);
            return(View(classroomallocation));
        }
        // GET: ClassRoomAllocation/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ClassRoomAllocation classRoomAllocation = db.ClassRoomAllocations.Find(id);

            if (classRoomAllocation == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CourseId     = new SelectList(db.Courses, "CourseId", "CourseCode", classRoomAllocation.CourseId);
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "DepartmentName", classRoomAllocation.DepartmentId);
            ViewBag.RoomId       = new SelectList(db.Rooms, "RoomId", "RoomNo", classRoomAllocation.RoomId);
            return(View(classRoomAllocation));
        }
예제 #21
0
        public int Save(ClassRoomAllocation allocation)
        {
            string query = "INSERT INTO ClassRoomAllocation VALUES(@courseId,@roomId,@dayId,@fromTime,@toTime,@status)";

            Command = new SqlCommand(query, Connection);
            Command.Parameters.AddWithValue("@courseId", allocation.CourseId);
            Command.Parameters.AddWithValue("@roomId", allocation.RoomId);
            Command.Parameters.AddWithValue("@dayId", allocation.DayId);
            Command.Parameters.AddWithValue("@fromTime", allocation.FromTime);
            Command.Parameters.AddWithValue("@toTime", allocation.ToTime);
            Command.Parameters.AddWithValue("@status", allocation.Status);

            Connection.Open();
            int rowAffect = Command.ExecuteNonQuery();

            Connection.Close();
            return(rowAffect);
        }
예제 #22
0
        public bool IsToTimeSAllocated(ClassRoomAllocation allocation)
        {
            string query = "SELECT * FROM ClassRoomAllocation WHERE  DayId=@dayId AND RoomId=@roomId AND ToTime BETWEEN @fromTime AND @toTime AND Status='Allocated";

            Command = new SqlCommand(query, Connection);
            Command.Parameters.AddWithValue("@dayId", allocation.DayId);
            Command.Parameters.AddWithValue("@roomId", allocation.RoomId);
            Command.Parameters.AddWithValue("@fromTime", allocation.FromTime);
            Command.Parameters.AddWithValue("@toTime", allocation.ToTime);


            Connection.Open();
            Reader = Command.ExecuteReader();
            bool isExists = Reader.HasRows;

            Connection.Close();
            return(isExists);
        }
        public int Save(ClassRoomAllocation classRoomAllocation)
        {
            Query   = "INSERT INTO AllocateClassRoom VALUES(@DepartmentID,@CourseID,@RoomID,@Day,@FromTime,@ToTime)";
            Command = new SqlCommand(Query, Connection);
            Command.Parameters.AddWithValue("DepartmentID", classRoomAllocation.DepartmentID);
            Command.Parameters.AddWithValue("CourseID", classRoomAllocation.CourseID);
            Command.Parameters.AddWithValue("RoomID", classRoomAllocation.RoomID);
            Command.Parameters.AddWithValue("Day", classRoomAllocation.Day);
            Command.Parameters.AddWithValue("FromTime",
                                            classRoomAllocation.FromTimeHour + " " + classRoomAllocation.FromTimePeriod);
            Command.Parameters.AddWithValue("ToTime",
                                            classRoomAllocation.ToTimeHour + " " + classRoomAllocation.ToTimePeriod);
            Connection.Open();
            int rowAffected = Command.ExecuteNonQuery();

            Connection.Close();
            return(rowAffected);
        }
예제 #24
0
        public string AllocateNewClassRoom(ClassRoomAllocation classRoomAllocation)
        {
            if (!aClassRoomGateway.IsAllocationPossible(classRoomAllocation))
            {
                return("Not Possible");
            }
            else
            {
                int rowAffected = aClassRoomGateway.AllocateNewClassRoom(classRoomAllocation);

                if (rowAffected > 0)
                {
                    return("Class Room Allocated Successfully!!");
                }
                else
                {
                    return("Allocated Failed!!");
                }
            }
        }
예제 #25
0
        public int AllocateNewClassRoom(ClassRoomAllocation classRoomAllocation)
        {
            string query = @"insert into ClassRoomAllocation (TimeFrom, TimeTo,Status,DepartmentId,CourseId,RoomNoId,SevenDayWeekId) values(@TimeFrom, @TimeTo,@Status,@DepartmentId,@CourseId,@RoomNoId,@SevenDayWeekId)";

            cmd = new SqlCommand(query, connection);
            //cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@TimeFrom", classRoomAllocation.TimeFrom);
            cmd.Parameters.AddWithValue("@TimeTo", classRoomAllocation.TimeTo);
            cmd.Parameters.AddWithValue("@Status", "0");
            cmd.Parameters.AddWithValue("@DepartmentId", classRoomAllocation.DepartmentId);

            cmd.Parameters.AddWithValue("@CourseId", classRoomAllocation.CourseId);
            cmd.Parameters.AddWithValue("@RoomNoId", classRoomAllocation.RoomNoId);
            cmd.Parameters.AddWithValue("@SevenDayWeekId", classRoomAllocation.SevenDayWeekId);

            connection.Open();
            int rowAffect = cmd.ExecuteNonQuery();

            connection.Close();
            return(rowAffect);
        }
 public string Save(ClassRoomAllocation aClassRoom)
 {
     try
     {
         if (aRoomGateway.isexist(aClassRoom))
         {
             return("Please select different Time");
         }
         else if (aRoomGateway.Save(aClassRoom) > 0)
         {
             return("Room Allocated Successfully");
         }
         else
         {
             return("Room Allocation Failed");
         }
     }
     catch (Exception)
     {
         return("Room Allocation Failed");
     }
 }
        // UniversityManager universityManager = new UniversityManager();

        // GET: ClassRoomAllocation
        public ActionResult Index(int departmentId = 0)
        {
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "DepartmentName", departmentId);
            var classRoomAllocations = db.ClassRoomAllocations.Include(c => c.Course).Include(c => c.Department).Include(c => c.Room).ToList().FindAll(c => (c.DepartmentId == departmentId) && (c.IsAllocated == true));

            if (departmentId != 0)
            {
                var courses = db.Courses.ToList().FindAll(c => c.DepartmentId == departmentId);
                foreach (var course in courses)
                {
                    if (!classRoomAllocations.Exists(c => c.CourseId == course.CourseId))
                    {
                        ClassRoomAllocation aClassRoomAllocation = new ClassRoomAllocation();
                        aClassRoomAllocation.Course = course;

                        classRoomAllocations.Add(aClassRoomAllocation);
                    }
                }
                return(View(classRoomAllocations));
            }
            return(View(classRoomAllocations));
        }
 public ActionResult Index(ClassRoomAllocation classRoomAllocation)
 {
     if (ModelState.IsValid)
     {
         ViewBag.Departments          = new TeacherController().GetAllDepartmentList();
         ViewBag.ClassRooms           = GetAllClassRoomList();
         ViewBag.Days                 = GetAllWeekDayList();
         classRoomAllocation.TimeFrom = classRoomAllocation.TimeFrom.Remove(2, 1);
         classRoomAllocation.TimeTo   = classRoomAllocation.TimeTo.Remove(2, 1);
         ViewBag.Message              = new ClassRoomManager().AllocateNewClassRoom(classRoomAllocation);
         ModelState.Clear();
         return(View());
     }
     else
     {
         ViewBag.Message     = "";
         ViewBag.Departments = new TeacherController().GetAllDepartmentList();
         ViewBag.ClassRooms  = GetAllClassRoomList();
         ViewBag.Days        = GetAllWeekDayList();
         return(View());
     }
 }
예제 #29
0
        public List <ClassRoomAllocation> IsTimeScheduleAllocated(ClassRoomAllocation allocation)
        {
            string query = "SELECT * FROM ClassRoomAllocation WHERE  DayId=@dayId AND RoomId=@roomId AND Status='Allocated'";

            Command = new SqlCommand(query, Connection);
            Command.Parameters.AddWithValue("@dayId", allocation.DayId);
            Command.Parameters.AddWithValue("@roomId", allocation.RoomId);
            Connection.Open();
            Reader = Command.ExecuteReader();
            List <ClassRoomAllocation> classRoomAllocationsList = new List <ClassRoomAllocation>();
            ClassRoomAllocation        classRoom = new ClassRoomAllocation();

            if (Reader.Read())
            {
                classRoom.FromTime = Reader["FromTime"].ToString();
                classRoom.ToTime   = Reader["ToTime"].ToString();
                classRoom.Status   = Reader["Status"].ToString();
            }
            classRoomAllocationsList.Add(classRoom);
            Connection.Close();
            return(classRoomAllocationsList);
        }
        private bool AllocateClassRoom(ClassRoomAllocation classRoomAllocation)
        {
            var  allocations = db.ClassRoomAllocations.ToList().FindAll(l => l.RoomId == classRoomAllocation.RoomId && l.Day == classRoomAllocation.Day && l.IsAllocated == true);
            bool possible    = true;

            foreach (var allocation in allocations)
            {
                var ps = allocation.StartTime;
                var pe = allocation.EndTime;

                if ((classRoomAllocation.StartTime <= ps && classRoomAllocation.EndTime <= ps) || (classRoomAllocation.StartTime >= pe && classRoomAllocation.EndTime >= pe))
                {
                    possible = true;
                }

                else
                {
                    possible = false;
                    break;
                }
            }
            return(possible);
        }