}//Regular expression check for room code

        private bool validate(string roomCode) //Checks that room with same name hasn't been created before
        {
            bool returnVal = false;

            using (var db = new TimetableDbEntities())
            {
                //Get all roomID where the roomName is the same as the one the user inputted
                var room = from roomDB in db.Rooms where roomDB.roomCode == roomCode select roomDB.roomCode;

                if (room.Count() == 0)
                {
                    //Allows room to be created if there are no existing rooms with same name
                    returnVal = true;
                }
            }

            return(returnVal);
        }
Exemplo n.º 2
0
        private bool validateDetails(string deptIn, string password)
        {
            bool returnVal = false;

            using (var db = new TimetableDbEntities())
            {
                var user = from userDB in db.Users from dInfoDB in db.DeptInfoes where userDB.deptID == dInfoDB.deptID && dInfoDB.deptName == deptIn select userDB.email;

                // search for email, i.e. username, email = uniq to display. Are doing usernames or just depts?

                if (user.FirstOrDefault() != null)
                {
                    var inputPass = from userDB in db.Users from dInfoDB in db.DeptInfoes where userDB.deptID == dInfoDB.deptID && dInfoDB.deptName == deptIn select userDB.password;

                    if (inputPass.FirstOrDefault() == password)
                    {
                        returnVal = true;
                    }
                }
            }

            return(returnVal);
        }
Exemplo n.º 3
0
        [HttpPost] // validation - rtn deptlogin from input, validate
        public ActionResult Index(Models.LoginModel deptLogin)
        {
            if (ModelState.IsValid)
            {
                if (validateDetails(deptLogin.deptIn, deptLogin.password))
                {
                    int userId = 0;
                    using (var db = new TimetableDbEntities())
                    {
                        var userID = from deptTable in db.DeptInfoes where deptTable.deptName == deptLogin.deptIn select deptTable.deptID;
                        userId = userID.FirstOrDefault();


                        var db2 = new TimetableDbEntities();

                        var isAdmin = db2.Users.Where(a => a.userID == userId).Select(b => b.admin).First();

                        TempData["usrId"]     = userId;
                        TempData["deptLogin"] = deptLogin.deptIn;

                        if (isAdmin == 0)
                        {
                            return(RedirectToAction("Index", "View"));;
                        }
                        else
                        {
                            return(RedirectToAction("Index", "AdminRequests"));;
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Your details are invalid.");
                }
            }
            return(View());
        }
        // GET: Timetable
        public ActionResult Index(string modOrLec, string nameOrCode, int?week, int?getSemester)
        {
            //dskufhsdjkfhaidsuf
            var db        = new TimetableDbEntities();
            var getLec    = db.LecturerInfoes.Where(f => f.deptID == userLogged.usrId).Select(f => f.name).ToList();
            var getCourse = db.DegreeInfoes.Where(d => d.deptID == userLogged.usrId).Select(o => o.degreeName).ToList();


            @ViewBag.getLec    = getLec;
            @ViewBag.getCourse = getCourse;

            if (modOrLec != null && nameOrCode != null && week != null && getSemester != null)
            {
                var getLecID = db.DegreeInfoes.Where(a => a.degreeName == nameOrCode).Select(b => b.Modules.Select(c => c.moduleID)).FirstOrDefault();

                if (modOrLec == "Lecturer")
                {
                    getLecID = db.LecturerInfoes.Where(a => a.name == nameOrCode).Select(b => b.Modules.Select(c => c.moduleID)).FirstOrDefault();
                }


                if (getLecID != null)
                {
                    IEnumerable <int> temp = getLecID; // do try catch incase index out of range

                    var getWeekID = db.Requests.Where(x => temp.Contains((int)x.moduleID)).Select(x => x.week).ToList();
                    var getReqID  = new List <Scotthi>();
                    foreach (var a in getWeekID)
                    {
                        var aNew = a.Replace("[", "");

                        var aNew2 = aNew.Replace("]", "");

                        string[] weekIDs = aNew2.Split(new char[] { ',' });

                        List <int> weekIDs2 = new List <int>();//all week IDs will be put in here


                        if (weekIDs[(int)week - 1] == "1")
                        {
                            var tempxxx = db.Requests.Where(x => temp.Contains((int)x.moduleID) && x.semester == getSemester && x.week == a).Select(x => new Scotthi {
                                reqID = x.requestID, periodID = x.periodID, semester = x.semester, week = x.week, dayID = x.dayID, moduleID = x.moduleID, sessionTypeID = x.sessionTypeID
                            }).FirstOrDefault();

                            if (tempxxx != null)
                            {
                                getReqID.Add(tempxxx);
                            }
                        }
                    }

                    foreach (var p in getReqID)
                    {
                        var moduleCode = db.Requests.Join(db.Modules, a => a.moduleID, d => d.moduleID, (a, d) => new { a.moduleID, d.modCode }).Where(a => a.moduleID == p.moduleID).Select(d => d.modCode);

                        var moduleName = db.Requests.Join(db.Modules, a => a.moduleID, d => d.moduleID, (a, d) => new { a.moduleID, d.modTitle }).Where(a => a.moduleID == p.moduleID).Select(d => d.modTitle);

                        var type = db.Requests.Join(db.SessionTypeInfoes, a => a.sessionTypeID, d => d.sessionTypeID, (a, d) => new { a.sessionTypeID, d.sessionType }).Where(a => a.sessionTypeID == p.sessionTypeID).Select(d => d.sessionType);

                        var weeks = db.Requests.Select(a => a.week).FirstOrDefault();

                        var roomID = db.Requests.Where(a => a.requestID == p.reqID).Select(a => a.RoomRequests.Select(b => b.roomID)).FirstOrDefault();

                        var getRoomCode = db.Rooms.Where(a => a.roomID == roomID.FirstOrDefault()).Select(b => b.roomCode).First();

                        var getBuildingID = db.Rooms.Where(a => a.roomCode == getRoomCode).Select(b => b.buildingID).FirstOrDefault();

                        var getBuildingName = db.Buildings.Where(a => a.buildingID == getBuildingID).Select(b => b.buildingName).FirstOrDefault();

                        var sessionLength = db.Requests.Where(a => a.requestID == p.reqID).Select(b => b.sessionLength).FirstOrDefault();



                        @ViewBag.error         = "good";
                        @ViewBag.req           = p;
                        @ViewBag.moduleCode    = moduleCode.FirstOrDefault();
                        @ViewBag.moduleName    = moduleName.FirstOrDefault();
                        @ViewBag.type          = type.FirstOrDefault();
                        @ViewBag.weeks         = formatWeeks(weeks);
                        @ViewBag.roomCode      = getRoomCode;
                        @ViewBag.buildingName  = getBuildingName;
                        @ViewBag.sessionLength = sessionLength;
                    }
                }
            }
            else
            {
                @ViewBag.error = "";
            }
            return(View());
        }
        //
        // GET: /View/
        public ActionResult Index(string sortOrder, int?roundID, int?cancelledID, string moduleCode, int?semester, int?day, int?status, int?year)
        {
            //get db and run query

            if (userLogged.UserName == null)
            {
                userLogged.UserName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase((String)TempData["deptLogin"]);
                userLogged.usrId    = (int)TempData["usrId"];
            }



            var db          = new TimetableDbEntities();
            var getRequests = from t in db.Requests
                              select t;

            var getRounds = from t in db.RoundInfoes select t.round;

            @ViewBag.rounds = getRounds;

            var moduleCodes = db.Modules.Where(f => f.deptID == userLogged.usrId).Select(a => a.modCode).ToList();
            var lecturer    = db.LecturerInfoes.Where(f => f.deptID == userLogged.usrId).Select(a => a.name).ToList();

            List <string> codeOrName = new List <string>();

            codeOrName.Add(moduleCode);
            //codeOrName.Add(lecturer);
            @ViewBag.moduleCodes = moduleCodes;

            if (roundID != null)
            {
                getRequests = getRequests.Where(t => t.round == roundID);
            }
            if (moduleCode != null && moduleCode != "")
            {
                var getModID = db.Modules.Where(t => t.modCode == moduleCode).Select(o => o.moduleID).FirstOrDefault();

                getRequests = getRequests.Where(t => t.moduleID == getModID);
            }
            if (semester != null)
            {
                getRequests = getRequests.Where(t => t.semester == semester);
            }
            if (day != null)
            {
                getRequests = getRequests.Where(t => t.dayID == day);
            }
            if (status != null)
            {
                getRequests = getRequests.Where(t => t.statusID == status);
            }



            if (cancelledID != null)
            {
                //var deleteRequest = (from del in db.Requests where del.requestID == cancelledID select del).First();
                // you want to change.
                var updateStatus =
                    (from del in db.Requests
                     where del.requestID == cancelledID
                     select del).Single();

                updateStatus.statusID = 5;
                db.SaveChanges();
            }



            if (year == 2014)
            {
                getRequests = getRequests.Where(t => t.year == 2014);
            }
            if (year == 2015 || year == null)
            {
                getRequests = getRequests.Where(t => t.year == 2015);
            }



            //sort dependent from view
            ViewBag.IDSortPram     = String.IsNullOrEmpty(sortOrder) ? "id_desc" : "";
            ViewBag.ModuleSortPram = sortOrder == "Module" ? "module_desc" : "Module";
            ViewBag.DateSortPram   = sortOrder == "Date" ? "date_desc" : "Date";
            var reqArray = getRequests.ToArray();

            //switch and run sort
            switch (sortOrder)
            {
            case "id_desc":
                getRequests = getRequests.OrderByDescending(s => s.requestID);
                reqArray    = getRequests.ToArray();
                break;

            case "Date":
                getRequests = getRequests.OrderByDescending(s => s.year);
                reqArray    = getRequests.ToArray();
                break;

            case "date_desc":
                getRequests = getRequests.OrderBy(s => s.year);
                reqArray    = getRequests.ToArray();
                break;

            case "Module":
                getRequests = getRequests.OrderBy(f => f.Module.modCode);
                reqArray    = getRequests.ToArray();
                break;

            case "module_desc":
                getRequests = getRequests.OrderByDescending(s => s.moduleID);
                reqArray    = getRequests.ToArray();
                break;

            default:
                getRequests = getRequests.OrderBy(s => s.requestID);
                reqArray    = getRequests.ToArray();
                break;
            }



            List <Models.ViewModel> requestList = new List <Models.ViewModel>();

            foreach (var x in reqArray)
            {
                Models.ViewModel tmp = new Models.ViewModel();


                tmp.requestID          = x.requestID;
                tmp.moduleID           = x.moduleID;
                tmp.periodID           = x.periodID;
                tmp.priority           = x.priority;
                tmp.round              = x.round;
                tmp.semester           = x.semester;
                tmp.sessionLength      = x.sessionLength;
                tmp.sessionTypeID      = x.sessionTypeID;
                tmp.specialRequirement = x.specialRequirement;
                tmp.statusID           = x.statusID;
                tmp.year   = x.year;
                tmp.dayID  = x.dayID;
                tmp.adhoc  = x.adhoc;
                tmp.userID = x.userID;
                tmp.weekID = formatWeeks(x.week);

                var roomCodes = db.Requests.Join(db.Modules, a => a.moduleID, d => d.moduleID, (a, d) => new { a.moduleID, d.modCode }).Where(a => a.moduleID == x.moduleID).Select(d => d.modCode);

                tmp.moduleCode = roomCodes.FirstOrDefault();
                //var roomCodeName = db.Requests.Where(a => a.requestID == x.requestID).Select(a => a.RoomRequests.Select(c => c.ToList()).ToList();

                var roomCodeName = db.Requests.Where(a => a.requestID == x.requestID).Select(a => a.RoomRequests.Select(c => c.roomID)).FirstOrDefault();

                var           roomIDList = roomCodeName;
                List <string> roomCodes2 = new List <string>();
                foreach (var i in roomIDList)
                {
                    var getRoomCode = db.Rooms.Where(a => a.roomID == i).Select(b => b.roomCode).First();
                    roomCodes2.Add(getRoomCode);
                }
                tmp.room = roomCodes2;
                var dayName = db.Requests.Join(db.DayInfoes, a => a.dayID, d => d.dayID, (a, d) => new { a.dayID, d.day }).Where(a => a.dayID == x.dayID).Select(d => d.day);
                tmp.day = dayName.FirstOrDefault();

                var statusName = db.Requests.Join(db.StatusInfoes, a => a.statusID, d => d.statusID, (a, d) => new { a.statusID, d.status }).Where(a => a.statusID == x.statusID).Select(d => d.status);
                tmp.status = statusName.FirstOrDefault();



                var sessionTypeName = db.Requests.Join(db.SessionTypeInfoes, a => a.sessionTypeID, d => d.sessionTypeID, (a, d) => new { a.sessionTypeID, d.sessionType }).Where(a => a.sessionTypeID == x.sessionTypeID).Select(d => d.sessionType);
                tmp.sessionType = sessionTypeName.FirstOrDefault();

                var email = db.Requests.Join(db.Users, a => a.userID, d => d.userID, (a, d) => new { a.userID, d.email }).Where(a => a.userID == x.userID).Select(d => d.email);
                tmp.email = email.FirstOrDefault();
                requestList.Add(tmp);
            }

            var example = requestList.ToList();

            return(View(requestList));
        }