public void AddAccomodationRequest(AccomodationRequest model, Student student) { Student stud = db.Students.FirstOrDefault(item => item.Id == student.Id); if (stud.AccomodationRequestId == null) { AccomodationRequest accReq = new AccomodationRequest(); foreach (Roommate roommate in model.ArRoommates) { if (roommate.FirstName != null) { Student studentRoommate = db.Students.FirstOrDefault(item => item.FirstName == roommate.FirstName && item.LastName == roommate.LastName && item.Initial == roommate.Initial); if (studentRoommate != null) { roommate.Student = studentRoommate; roommate.StudentId = studentRoommate.Id; accReq.ArRoommates.Add(roommate); } } } foreach (DormsPreferred dorm in model.ArDorm) { if (dorm.DormName != null) { Dorm d = db.Dorms.FirstOrDefault(item => item.DormName == dorm.DormName); if (d != null) { dorm.Dorm = d; dorm.DormId = d.Id; accReq.ArDorm.Add(dorm); } } } foreach (RoomPreferred room in model.ArRoom) { if (room.RoomNo != null) { Room d = db.Rooms.FirstOrDefault(item => item.RoomNo.ToString() == room.RoomNo); if (d != null) { room.Room = d; room.RoomId = d.Id; accReq.ArRoom.Add(room); } } } accReq.LastComfortAccepted = model.LastComfortAccepted; stud.AccomodationRequest = accReq; stud.AccomodationRequestId = accReq.Id; db.AccomodationRequests.Add(accReq); db.Students.Update(stud); } }
public IActionResult ViewAccomodationRequest() { Student student = _repository.GetStudentById(AppController.student.Id); if (student.AccomodationRequestId.HasValue) { AccomodationRequest accomodationRequest = _repository.GetAccomodationRequestById((int)student.AccomodationRequestId); return(View(accomodationRequest)); } else { TempData["mess"] = "You have not sent an accomodation request yet!"; return(RedirectToAction("HomePageStudent", "HomePageStudent")); } }
public AccomodationRequest GetAccomodationRequestById(int id) { AccomodationRequest accomodation = db.AccomodationRequests.FirstOrDefault(item => item.Id == id); List <RoomPreferred> rooms = db.RoomPreferreds.Where(item => item.AccomodationRequestId == id).ToList(); var dorms = db.DormsPreferreds.Where(item => item.AccomodationRequestId == id).ToList(); var roommates = db.Roommates.Where(item => item.AccomodationRequestId == id).ToList(); accomodation.ArRoom = rooms; accomodation.ArDorm = dorms; accomodation.ArRoommates = roommates; if (accomodation == null) { return(null); } return(accomodation); }
public IActionResult Preferences(AccomodationRequest accomodationRequest) { Student stud = _repository.GetStudentByCNP(AppController.student.Cnp); if (!stud.AccomodationRequestId.HasValue) { _repository.AddAccomodationRequest(accomodationRequest, AppController.student); _repository.SaveAll(); TempData["mess"] = "Accomodation request sent!"; } else { TempData["mess"] = "Accomodation request already sent!"; } return(RedirectToAction("HomePageStudent", "HomePageStudent")); }
public void UploadAccomodationRequests(ExcelFile fileUpload) { var accomodations = new AccomodationRequest[_repository.GetAllStudents().Count()]; var file = fileUpload.FileAccomodationRequests; string folderName = "UploadAccomodationRequests"; string webRootPath = _hostingEnvironment.WebRootPath; string newPath = Path.Combine(webRootPath, folderName); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } if (file.Length > 0) { string sFileExtension = Path.GetExtension(file.FileName).ToLower(); ISheet sheet; string fullPath = Path.Combine(newPath, file.FileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); stream.Position = 0; if (sFileExtension == ".xls") { HSSFWorkbook hssfwb = new HSSFWorkbook(stream); //This will read the Excel 97-2000 formats sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } else { XSSFWorkbook hssfwb = new XSSFWorkbook(stream); //This will read 2007 Excel format sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } IRow headerRow = sheet.GetRow(0); //Get Header Row int cellCount = headerRow.LastCellNum; for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) //Read Excel File { IRow row = sheet.GetRow(i); if (row == null) { continue; } if (row.Cells.All(d => d.CellType == CellType.Blank)) { continue; } AccomodationRequest accomodationRequest = new AccomodationRequest(); for (int j = 0; j < 5; j++) { DormsPreferred dorm = new DormsPreferred(); if (row.GetCell(j + 1).ToString().Length > 0 && row.GetCell(j + 1).ToString() != "e") { dorm.DormName = row.GetCell(j + 1).ToString(); accomodationRequest.ArDorm.Add(dorm); } else { break; } } for (int k = 0; k < 5; k++) { if (row.GetCell(k + 6).ToString() != "e") { RoomPreferred room = new RoomPreferred(); room.RoomNo = row.GetCell(k + 6).ToString(); accomodationRequest.ArRoom.Add(room); } else { break; } } for (int l = 0; l < 2; l++) { if (row.GetCell(l + 11).ToString() != "e" && row.GetCell(l + 12).ToString() != "e" && row.GetCell(l + 13).ToString() != "e") { Roommate roommate = new Roommate(); roommate.FirstName = row.GetCell(l + 11).ToString(); roommate.LastName = row.GetCell(l + 12).ToString(); roommate.Initial = row.GetCell(l + 13).ToString(); accomodationRequest.ArRoommates.Add(roommate); } else { break; } } if (row.GetCell(17).ToString() != "e") { accomodationRequest.LastComfortAccepted = row.GetCell(17).ToString(); } //_repository.AddAccomodationRequestToDatabase(accomodationRequest); string cnp = row.GetCell(18).ToString(); Student student = _repository.GetStudentByCNP(cnp); student.AccomodationRequest = accomodationRequest; student.AccomodationRequestId = accomodationRequest.Id; _repository.UpdateStudent(student); } //var students = _repository.GetStudentsOrderdById().ToList(); //for (int i = 0; i < accomodations.Count; i++) //{ // students[i].AccomodationRequest = accomodations[i]; // students[i].AccomodationRequestId = accomodations[i].Id; //} } } }