public List <RequestsWtihLinkedData> GetHistory()
        {
            SemRouController srAPI = new SemRouController();

            IEnumerable <round> liveRounds   = srAPI.GetLiveRoundSet();
            List <int>          liveRoundsID = new List <int>();

            IEnumerable <round> adhocRounds   = srAPI.GetAdHocRoundSet();
            List <int>          adhocRoundsID = new List <int>();

            foreach (round rnd in liveRounds)
            {
                liveRoundsID.Add(rnd.id);
            }

            foreach (round rnd in adhocRounds)
            {
                adhocRoundsID.Add(rnd.id);
            }

            IEnumerable <request> requests =
                from req in _db.requests.Include("roomsAlloc").Include("roomsPref").Include("facilities").Include("module")
                where (req.status == 1 || req.status == 2)
                &&
                req.module.department.code == nsd.code
                &&
                !liveRoundsID.Contains(req.roundID)
                &&
                !adhocRoundsID.Contains(req.roundID)
                select req;

            List <RequestsWtihLinkedData> rwldList = new List <RequestsWtihLinkedData>();

            foreach (request req in requests)
            {
                RequestsWtihLinkedData rwld = new RequestsWtihLinkedData(req);

                rwldList.Add(rwld);
            }

            return(rwldList);
        }
        private request SetupNewRequestObject(RequestsWtihLinkedData rwld, bool current)
        {
            request newRequest = new request();

            module selectedModule =
                (from mod in _db.modules
                 where mod.code == rwld.moduleCode
                 select mod).FirstOrDefault();

            newRequest.moduleCode = selectedModule.code;
            newRequest.module = selectedModule;

            SemRouController srAPI = new SemRouController();

            round selectedRound;
            if (current) {

                selectedRound = srAPI.GetLiveRound();

                newRequest.status = rwld.status;

            }
            else
            {

                selectedRound = srAPI.GetAdHocRound();

                newRequest.status = 1;

            }

            newRequest.roundID = selectedRound.id;

            newRequest.priority = rwld.priority;
            newRequest.day = rwld.day;
            newRequest.startPeriod = rwld.startPeriod;
            newRequest.endPeriod = rwld.endPeriod;
            newRequest.weeks = rwld.weeks;
            newRequest.numberOfStudents = rwld.numberOfStudents;
            newRequest.parkPreference = rwld.parkPreference;
            newRequest.sessionType = rwld.sessionType;
            newRequest.numberOfRooms = rwld.numberOfRooms;
            newRequest.otherRequirements = rwld.otherRequirements;
            newRequest.traditional = rwld.traditional;

            foreach (var facData in rwld.facilities)
            {

                facility selectedFacility =
                    (from fac in _db.facilities
                     where fac.id == facData.id
                     select fac).FirstOrDefault();

                newRequest.facilities.Add(selectedFacility);

            }

            foreach (var roomData in rwld.roomPref)
            {

                room selectedRoom =
                    (from rm in _db.rooms
                     where rm.code == roomData.code
                     select rm).FirstOrDefault();

                newRequest.roomsPref.Add(selectedRoom);

            }

            if (!current)
            {

                foreach (var roomData in rwld.roomPref)
                {

                    room selectedRoom =
                        (from rm in _db.rooms
                         where rm.code == roomData.code
                         select rm).FirstOrDefault();

                    newRequest.roomsAlloc.Add(selectedRoom);

                }

            }

            return newRequest;
        }
        public List<RequestsWtihLinkedData> GetHistory()
        {
            SemRouController srAPI = new SemRouController();

            IEnumerable<round> liveRounds = srAPI.GetLiveRoundSet();
            List<int> liveRoundsID = new List<int>();

            IEnumerable<round> adhocRounds = srAPI.GetAdHocRoundSet();
            List<int> adhocRoundsID = new List<int>();

            foreach (round rnd in liveRounds)
            {
                liveRoundsID.Add(rnd.id);
            }

            foreach (round rnd in adhocRounds)
            {
                adhocRoundsID.Add(rnd.id);
            }

            IEnumerable<request> requests =
                from req in _db.requests.Include("roomsAlloc").Include("roomsPref").Include("facilities").Include("module")
                where (req.status == 1 || req.status == 2)
                        &&
                        req.module.department.code == nsd.code
                        &&
                        !liveRoundsID.Contains(req.roundID)
                        &&
                        !adhocRoundsID.Contains(req.roundID)
                select req;

            List<RequestsWtihLinkedData> rwldList = new List<RequestsWtihLinkedData>();

            foreach (request req in requests)
            {
                RequestsWtihLinkedData rwld = new RequestsWtihLinkedData(req);

                rwldList.Add(rwld);
            }

            return rwldList;
        }
        private request SetupNewRequestObject(RequestsWtihLinkedData rwld, bool current)
        {
            request newRequest = new request();

            module selectedModule =
                (from mod in _db.modules
                 where mod.code == rwld.moduleCode
                 select mod).FirstOrDefault();

            newRequest.moduleCode = selectedModule.code;
            newRequest.module     = selectedModule;

            SemRouController srAPI = new SemRouController();

            round selectedRound;

            if (current)
            {
                selectedRound = srAPI.GetLiveRound();

                newRequest.status = rwld.status;
            }
            else
            {
                selectedRound = srAPI.GetAdHocRound();

                newRequest.status = 1;
            }

            newRequest.roundID = selectedRound.id;

            newRequest.priority          = rwld.priority;
            newRequest.day               = rwld.day;
            newRequest.startPeriod       = rwld.startPeriod;
            newRequest.endPeriod         = rwld.endPeriod;
            newRequest.weeks             = rwld.weeks;
            newRequest.numberOfStudents  = rwld.numberOfStudents;
            newRequest.parkPreference    = rwld.parkPreference;
            newRequest.sessionType       = rwld.sessionType;
            newRequest.numberOfRooms     = rwld.numberOfRooms;
            newRequest.otherRequirements = rwld.otherRequirements;
            newRequest.traditional       = rwld.traditional;

            foreach (var facData in rwld.facilities)
            {
                facility selectedFacility =
                    (from fac in _db.facilities
                     where fac.id == facData.id
                     select fac).FirstOrDefault();

                newRequest.facilities.Add(selectedFacility);
            }

            foreach (var roomData in rwld.roomPref)
            {
                room selectedRoom =
                    (from rm in _db.rooms
                     where rm.code == roomData.code
                     select rm).FirstOrDefault();

                newRequest.roomsPref.Add(selectedRoom);
            }

            if (!current)
            {
                foreach (var roomData in rwld.roomPref)
                {
                    room selectedRoom =
                        (from rm in _db.rooms
                         where rm.code == roomData.code
                         select rm).FirstOrDefault();

                    newRequest.roomsAlloc.Add(selectedRoom);
                }
            }


            return(newRequest);
        }