public ActionResult Create([Bind(Include = "round,startDate,endDate")] RoundInfo roundInfo) { ViewBag.error = ""; var testStart = roundInfo.startDate; var testEnd = roundInfo.endDate; //Check start date is before end date var tStartDay = Convert.ToInt16(testStart.Substring(0, 2)); var tStartMonth = Convert.ToInt16(testStart.Substring(3, 2)); var tStartYear = Convert.ToInt16(testStart.Substring(6)); var tEndDay = Convert.ToInt16(testEnd.Substring(0, 2)); var tEndMonth = Convert.ToInt16(testEnd.Substring(3, 2)); var tEndYear = Convert.ToInt16(testEnd.Substring(6)); if (ModelState.IsValid && tStartYear < tEndYear || (tStartYear == tEndYear && tStartMonth < tEndMonth) || (tStartYear == tEndYear && tStartMonth == tEndMonth && tStartDay < tEndDay)) { db.RoundInfoes.Add(roundInfo); db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.error = "End date before start date"; return(View(roundInfo)); } }
public ActionResult Create([Bind(Include = "facilityID,facilityName")] Facility facility) { ViewBag.error = ""; if (!checkDuplicate(facility.facilityName)) { ViewBag.error = "Facility already exists"; return(View(facility)); } if (ModelState.IsValid && checkDuplicate(facility.facilityName)) { db.Facilities.Add(facility); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(facility)); }
protected void pushToDb(List <string> room_names, List <string> facility_names, Int16 module_id, Int16 session_type, string weeks, Int16 statusID, Int16?day, Int16 periodID, Int16 sessionLength, Int16 semester, Int16 round, Int16 adhoc, Int16 prio, Int16 year) { Request toSubmit = new Request() { userID = 2, // sort moduleID = module_id, sessionTypeID = session_type, dayID = day, periodID = periodID, sessionLength = sessionLength, semester = semester, round = round, year = year, priority = prio, // SORT adhoc = adhoc, specialRequirement = "There must be poop provided", statusID = statusID, week = weeks }; foreach (var i in facility_names) { toSubmit.Facilities.Add(_db.Facilities.Where(a => a.facilityName == i).FirstOrDefault()); } foreach (var j in room_names) { RoomRequest temp = new RoomRequest() { roomID = _db.Rooms.Where(a => a.roomCode == j).Select(b => b.roomID).FirstOrDefault(), groupSize = 50 }; toSubmit.RoomRequests.Add(temp); } _db.Requests.Add(toSubmit); _db.SaveChanges(); }
public ActionResult Create([Bind(Include = "roomCode,buildingID,capacity,Facilities")] Room room, bool Labe, IEnumerable <int> fac) { ViewBag.error = ""; if (room.roomCode == null || room.roomCode.IndexOf(".") == -1) { ViewBag.error = "Room code not given"; var options = db.Buildings.AsEnumerable().Select(s => new { buildingID = s.buildingID, Info = string.Format("{0} - {1}", s.buildingCode, s.buildingName) }); var facilityNames = db.Facilities.ToList(); ViewBag.facilities = facilityNames; ViewBag.buildingID = new SelectList(options, "buildingID", "Info"); return(View(room)); } room.roomCode = roomCodeToUpper(room.roomCode); var bID = room.buildingID; var bCode = room.roomCode; bCode = bCode.Substring(0, bCode.IndexOf(".")); var result = db.Buildings.Where(s => s.buildingCode.Contains(bCode)).Select(s => s.buildingID); if (result.First() != bID) { ViewBag.error = "Building code doesn't match code stated in room"; } else if (!checkRoomCode(room.roomCode)) { ViewBag.error = "Room code not in right format"; } else if (!validate(room.roomCode)) { ViewBag.error = "Room code already exists"; } else if (room.capacity < 1 || room.capacity > 400) { ViewBag.error = "Room capacity exceeds range. Capacity limit is 1 - 400."; } if (result.First() == bID && checkRoomCode(room.roomCode) && validate(room.roomCode) && ModelState.IsValid && (room.capacity >= 1 && room.capacity <= 400)) { room.@private = 0; if (Labe) { room.lab = 1; } else { room.lab = 0; } if (fac != null) { foreach (var i in fac) { //Gets facility object from db for correct id and adds it to room room.Facilities.Add(db.Facilities.Where(a => a.facilityID == i).First()); } } db.Rooms.Add(room); db.SaveChanges(); return(RedirectToAction("Index")); } var options2 = db.Buildings.AsEnumerable().Select(s => new { buildingID = s.buildingID, Info = string.Format("{0} - {1}", s.buildingCode, s.buildingName) }); var facilityNames2 = db.Facilities.ToList(); ViewBag.facilities = facilityNames2; ViewBag.buildingID = new SelectList(options2, "buildingID", "Info"); return(View(room)); }
public ActionResult Create(Models.CreateRoomModel room, bool Labe, IEnumerable <int> fac) { //Error when no building chosen ViewBag.error = ""; Room room1 = new Room(); //Data for new room instance room1.roomCode = room.roomCode; room1.capacity = room.capacity; room1.buildingID = room.buildingID; room1.lab = isLab(Labe); room1.@private = 1; if (room.roomCode == null || room.roomCode.IndexOf(".") == -1) { ViewBag.error = "Room code not given"; var buildings = db.DeptInfoes.Where(a => a.deptID == 5).Select(b => b.Buildings.Select(c => c.buildingID)).ToList(); List <Building> validBuildings = new List <Building>(); foreach (var i in buildings[0]) { var query = db.Buildings.Where(a => a.buildingID == i).First(); validBuildings.Add(query); } var options = validBuildings.AsEnumerable().Select(s => new { buildingID = s.buildingID, Info = string.Format("{0} - {1}", s.buildingCode, s.buildingName) }); var facilityNames = db.Facilities.ToList(); ViewBag.facilities = facilityNames; ViewBag.buildingID = new SelectList(options, "buildingID", "Info"); return(View()); } room1.roomCode = roomCodeToUpper(room1.roomCode); var bID = room1.buildingID; var bCode = room1.roomCode; bCode = bCode.Substring(0, bCode.IndexOf(".")); var result = db.Buildings.Where(s => s.buildingCode.Contains(bCode)).Select(s => s.buildingID).FirstOrDefault(); if (result != bID) { ViewBag.error = "Building code doesn't match code stated in room"; } else if (!checkRoomCode(room1.roomCode)) { ViewBag.error = "Room code not in right format"; } else if (!validate(room1.roomCode)) { ViewBag.error = "Room code already exists"; } else if (room.capacity < 1 || room.capacity > 400) { ViewBag.error = "Room capacity exceeds range. Capacity limit is 1 - 400."; } if (ModelState.IsValid && validate(room1.roomCode) && result == bID && checkRoomCode(room1.roomCode) && (room.capacity >= 1 && room.capacity <= 400)) { if (fac != null) { foreach (var i in fac) { //Gets facility object from db for correct id and adds it to room room1.Facilities.Add(db.Facilities.Where(a => a.facilityID == i).First()); } } // Add the new object to the Rooms table. db.Rooms.Add(room1); db.SaveChanges(); return(RedirectToAction("Index")); } var buildings2 = db.DeptInfoes.Where(a => a.deptID == 5).Select(b => b.Buildings.Select(c => c.buildingID)).ToList(); List <Building> validBuildings2 = new List <Building>(); foreach (var i in buildings2[0]) { var query = db.Buildings.Where(a => a.buildingID == i).First(); validBuildings2.Add(query); } var options2 = validBuildings2.AsEnumerable().Select(s => new { buildingID = s.buildingID, Info = string.Format("{0} - {1}", s.buildingCode, s.buildingName) }); var facilityNames2 = db.Facilities.ToList(); ViewBag.facilities = facilityNames2; ViewBag.buildingID = new SelectList(options2, "buildingID", "Info"); return(View(room1)); }
// GET: Admin Requests public ActionResult Index(string sortOrder, int?roundID, int?alterID, int?acceptID, int?allocateID, int?rejectID, int?moduleCode, int?semester, int?day, int?status, int?year) { //get db and run query var getRequests = db.Requests.Where(a => a.statusID == 4); if (roundID != null) { getRequests = getRequests.Where(t => t.round == roundID); } if (moduleCode != null) { getRequests = getRequests.Where(t => t.moduleID == moduleCode); } 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 (allocateID != null) { var updateStatus = db.Requests.Where(a => a.requestID == allocateID).First(); return(RedirectToAction("Allocate", new { id = allocateID })); } if (alterID != null) { var updateStatus = db.Requests.Where(a => a.requestID == alterID).First(); return(RedirectToAction("Edit", new { id = alterID })); } if (acceptID != null) { //var deleteRequest = (from del in db.Requests where del.requestID == cancelledID select del).First(); // you want to change. var updateStatus = db.Requests.Where(a => a.requestID == acceptID).First(); updateStatus.statusID = 1; db.SaveChanges(); } if (rejectID != null) { //var deleteRequest = (from del in db.Requests where del.requestID == cancelledID select del).First(); // you want to change. var updateStatus = db.Requests.Where(a => a.requestID == rejectID).First(); updateStatus.statusID = 2; 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(s => s.moduleID); 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.AdminRequestModel> requestList = new List <Models.AdminRequestModel>(); foreach (var x in reqArray) { Models.AdminRequestModel tmp = new Models.AdminRequestModel(); 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)).ToList(); var roomIDList = roomCodeName.First(); 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)); }
// // 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)); }