Ejemplo n.º 1
0
        public HttpResponseMessage PostDeleteModules(List <string> dm)
        {
            if (ModelState.IsValid)
            {
                foreach (string mCode in dm)
                {
                    module deleteModule =
                        (from mod in _db.modules
                         where mod.code == mCode
                         select mod).FirstOrDefault();

                    deleteModule.active = false;

                    _db.Entry(deleteModule).CurrentValues.SetValues(deleteModule);

                    _db.SaveChanges();
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, dm);

            response.Headers.Location = new Uri(Url.Link("DefaultApi", null));
            return(response);
        }
Ejemplo n.º 2
0
        public HttpResponseMessage PostEditModule(List <EditModules> emList)
        {
            if (ModelState.IsValid)
            {
                foreach (EditModules em in emList)
                {
                    module editModule =
                        (from mod in _db.modules
                         where mod.code == em.originalCode
                         select mod).FirstOrDefault();

                    editModule.code  = em.newCode;
                    editModule.title = em.newTitle;

                    _db.Entry(editModule).CurrentValues.SetValues(editModule);

                    _db.SaveChanges();
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }


            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, emList);

            response.Headers.Location = new Uri(Url.Link("DefaultApi", null));
            return(response);
        }
Ejemplo n.º 3
0
        public HttpResponseMessage PostAddModules(List <NewModule> amList)
        {
            if (ModelState.IsValid)
            {
                foreach (NewModule nm in amList)
                {
                    module moduleCheck =
                        (from mod in _db.modules
                         where mod.code == nm.code
                         select mod).FirstOrDefault();

                    if (moduleCheck != null)
                    {
                        if (!moduleCheck.active)
                        {
                            _db.modules.Remove(moduleCheck);

                            _db.SaveChanges();
                        }
                        else
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.OK, "New modules could not be creatd. \nModule " + moduleCheck.code + " Already Exists"));
                        }
                    }

                    module addNewModule = new module();

                    addNewModule.code     = nm.code;
                    addNewModule.title    = nm.title;
                    addNewModule.deptCode = GetAuthorisedDepartment().code;
                    addNewModule.active   = true;

                    _db.modules.Add(addNewModule);
                }

                _db.SaveChanges();
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, amList);

            response.Headers.Location = new Uri(Url.Link("DefaultApi", null));
            return(response);
        }
Ejemplo n.º 4
0
        private request UpdateRequestObject(RequestsWtihLinkedData rwld, request currentReq)
        {
            module selectedModule =
                (from mod in _db.modules
                 where mod.code == rwld.moduleCode
                 select mod).FirstOrDefault();

            currentReq.moduleCode = selectedModule.code;
            currentReq.module     = selectedModule;

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


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

                currentReq.facilities.Add(selectedFacility);
            }

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

                currentReq.roomsPref.Add(selectedRoom);
            }



            IEnumerable <round> adHocRounds = (new SemRouController()).GetAdHocRoundSet();

            List <int> adHocRoundIDs = new List <int>();

            foreach (round rnd in adHocRounds)
            {
                adHocRoundIDs.Add(rnd.id);
            }

            if (adHocRoundIDs.IndexOf(currentReq.roundID) != -1)
            {
                currentReq.roomsAlloc.Clear();

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

                    currentReq.roomsAlloc.Add(selectedRoom);
                }
            }

            return(currentReq);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public HttpResponseMessage PostAddModules(List<NewModule> amList)
        {
            if (ModelState.IsValid)
            {

                foreach (NewModule nm in amList)
                {

                    module moduleCheck =
                        (from mod in _db.modules
                         where mod.code == nm.code
                         select mod).FirstOrDefault();

                    if (moduleCheck != null)
                    {

                        if (!moduleCheck.active)
                        {
                            _db.modules.Remove(moduleCheck);

                            _db.SaveChanges();
                        }
                        else return Request.CreateErrorResponse(HttpStatusCode.OK, "New modules could not be creatd. \nModule " + moduleCheck.code + " Already Exists");

                    }

                    module addNewModule = new module();

                    addNewModule.code = nm.code;
                    addNewModule.title = nm.title;
                    addNewModule.deptCode = GetAuthorisedDepartment().code;
                    addNewModule.active = true;

                    _db.modules.Add(addNewModule);

                }

                _db.SaveChanges();

            }
            else return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, amList);
            response.Headers.Location = new Uri(Url.Link("DefaultApi", null));
            return response;
        }