public async Task <ActionResult> Edit([Bind(Include = "ExamId,SubjectId,LocationId,ExamDateTime,ExamEndTime,QuestionAmount,AccessCode,CodeIssueDateTime,FullyCorrected,MaxMark,MinMark,AvgMark,NumOfParticipants,NumOfFails")] ExamSession examSession) { string user = User.Identity.GetUserId(); int?dept = (from u in db.Users where u.Id == user select u.DepartmentId).FirstOrDefault(); List <int> depts = new List <int>(from d in db.Departments where d.DepartmentId == dept || d.DepartmentParentId == dept select d.DepartmentId); if (ModelState.IsValid) { /* * if (!depts.Contains(examSession.RelatedSubject.DepartmentId)) * { * return RedirectToAction("Management", "Dashboard"); * } */ db.Entry(examSession).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("ExamManager", "Clerk")); } List <Subject> subjects = new List <Subject>(from s in db.Subjects where depts.Contains(s.RelatedDepartment.DepartmentId) select s); ViewBag.SubjectId = new SelectList(subjects, "SubjectId", "SubjectName"); ViewBag.LocationId = new SelectList(db.Locations, "LocationId", "Campus", examSession.LocationId); return(View(examSession)); }
public IActionResult AddExamSession(ExamSessionViewModel model) { if (ModelState.IsValid) { var optionsBuilder = new DbContextOptionsBuilder <AppDbContext>(); var unitOfWork = new UnitOfWork(new AppDbContext(optionsBuilder.Options)); //if (true/*(model.Start < DateTime.Now) || (model.End < DateTime.Now) || (model.Start > model.End)*/) //{ // ViewBag.Error = $"La de début doit etre inférieur à la date de fin"; // return View(model); //} var examSession = new ExamSession(); examSession.Start = model.Start ?? default(DateTime); examSession.End = model.End ?? default(DateTime); examSession.Name = model.Name; examSession.Description = model.Description; examSession.IsActive = true; unitOfWork.ExamSessions.Add(examSession); unitOfWork.Complete(); TempData["Message"] = "La session a été enregistrer avec succès"; return(RedirectToAction("AddExamSession"));; } return(View(model)); }
public async Task <ActionResult> Create([Bind(Include = "ExamId,SubjectId,LocationId,ExamDateTime,ExamEndTime,QuestionAmount,AccessCode,CodeIssueDateTime,FullyCorrected,MaxMark,MinMark,AvgMark,NumOfParticipants,NumOfFails")] ExamSession examSession) { if (ModelState.IsValid) { db.ExamSessions.Add(examSession); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } string user = User.Identity.GetUserId(); int? dept = (from u in db.Users where u.Id == user select u.DepartmentId).FirstOrDefault(); List <int> depts = new List <int>(from d in db.Departments where d.DepartmentId == dept || d.DepartmentParentId == dept select d.DepartmentId); List <Subject> subjects = new List <Subject>(from s in db.Subjects where depts.Contains(s.RelatedDepartment.DepartmentId) select s); ViewBag.SubjectId = new SelectList(subjects, "SubjectId", "SubjectName"); ViewBag.LocationId = new SelectList(db.Locations, "LocationId", "Campus", examSession.LocationId); return(View(examSession)); }
public ActionResult Learner(ApplicationUser user) { string student = User.Identity.GetUserName(); List <string> studentSubjects = new List <string>(from e in db.Enrollments where e.StudentId == student && e.FinalAssessment == Enrollment.Assessment.Pending select e.SubjectId); // ExamSession currentexam = new ExamSession(); currentexam = (from e in db.ExamSessions where studentSubjects.Contains(e.SubjectId) && e.ExamDateTime <= DateTime.Now && e.ExamEndTime >= DateTime.Now select e).FirstOrDefault(); ViewBag.Exam = null; ViewBag.Subject = null; if (currentexam != null) { ViewBag.Exam = currentexam.ExamId; ViewBag.Subject = currentexam.RelatedSubject.SubjectName; RedirectToAction("ValidateStudent", "Exams", new { examid = ViewBag.Exam }); // } return(View(user)); }
// get availabe exams for student without course type public static ExamCollection GetAvailabeExams(int id) { ExamCollection result = new ExamCollection(); string s = String.Format( " select DISTINCT * from Exam, ExamSession " + " where {0} not in (select Student_Exam.FK_StudID from Student_Exam where Exam.id " + " <> Student_Exam.FK_ExamID) and Exam.flag <> 0 " + " and Exam.id in (Select ExamSession.FK_ExamID from ExamSession) " + " and Exam.id in (select Exam_Course_Instructor.FK_ExamID " + "from Exam_Course_Instructor,Course_Student " + "where Course_Student.FK_CourseID = Exam_Course_Instructor.FK_CourseID) " + " and Exam.id = ExamSession.FK_ExamID ", id); DataTable dt = DBLayer.ExecuteQuery(s); for (int i = 0; i < dt.Rows.Count; i++) { Admin admin = new Admin(int.Parse(dt.Rows[i]["FK_AdminID"].ToString())); int ids = int.Parse(dt.Rows[i]["session_ID"].ToString()); ExamSession examSession = new ExamSession(ids, DateTime.Parse(dt.Rows[i]["session_date"].ToString()), new Exam(int.Parse(dt.Rows[i]["id"].ToString()), true, admin), admin); Exam exam = new Exam(Convert.ToInt32(dt.Rows[i]["id"]), (bool)dt.Rows[i]["flag"], admin); exam.ExamSessions = new ExamSessionCollection(); exam.ExamSessions.Add(examSession); result.Add(exam); } result = RearangeExams(result); result = getExamCourse(result); return(result); }
public async Task <ActionResult> Delete(string id) { if (id == null) { return(RedirectToAction("Index")); } ExamSession examSession = await db.ExamSessions.FindAsync(id); if (examSession == null) { return(RedirectToAction("Index")); } /* * * string user = User.Identity.GetUserId(); * * int? dept = (from u in db.Users where u.Id == user select u.DepartmentId).FirstOrDefault(); * * List<int> depts = new List<int>(from d in db.Departments where d.DepartmentId == dept || d.DepartmentParentId == dept select d.DepartmentId); * * if (depts.Contains(examSession.RelatedSubject.DepartmentId)) * { * return RedirectToAction("Management", "Dashboard"); * } */ return(View(examSession)); }
public ActionResult MakeCode() { string ingivilator = User.Identity.GetUserId(); string code = ""; ExamSession session = (from i in db.Invigilations where i.UserId == ingivilator && i.RelatedExamSession.ExamDateTime <= DateTime.Now && i.RelatedExamSession.ExamEndTime >= DateTime.Now select i.RelatedExamSession).FirstOrDefault(); //we get the list of invigilations that have not yet happened, related to this invigilation //List<Invigilation> invigilations = new List<Invigilation>(from i in db.Invigilations where i.UserId == ingivilator && i.RelatedExamSession.ExamDateTime >= DateTime.Now select i); int num; if (session == null) { code = "You do not have any Active Exam "; ViewBag.Exam = "You are not during any exam right now"; ViewBag.Code = code; return(View()); } Random rand = new Random(); for (int i = 0; i <= 5; i++) { num = rand.Next(0, 35); if (num < 10) { code = code + num; } else { code = code + (char)('A' + num - 9); } } //end for ExamSession toAlter = db.ExamSessions.Find(session.ExamId); if (toAlter != null) //it shouldn't be null if session has a value { toAlter.AccessCode = code; toAlter.CodeIssueDateTime = DateTime.Now; db.Entry(toAlter).State = EntityState.Modified; db.SaveChanges(); } ViewBag.Exam = session.RelatedSubject.SubjectName; ViewBag.Code = code; return(View()); }
/* * public ActionResult ExamPage(string examid) * { * * ExamSession exam = new ExamSession(); * exam = (from e in db.ExamSessions where e.ExamId == examid && e.FullyCorrected==false select e).FirstOrDefault(); * * ViewData["ExamId"] = examid; * ViewBag.Subject = exam.SubjectId; * List<PaperQuestion> paper = new List<PaperQuestion>(); * * paper =db.PaperQuestions.Where(x => x.ExamId == examid).ToList(); * * return View(paper); * } */ //[HttpPost] //public ActionResult ExamPage(List<PaperQuestion> paper) //public ActionResult ExamPage(string examid) public List <PaperQuestion> ExamPage(string examid) { ExamSession exam = new ExamSession(); exam = (from e in db.ExamSessions where e.ExamId == examid && e.FullyCorrected == false select e).FirstOrDefault(); ViewData["ExamId"] = examid; ViewBag.Subject = exam.SubjectId; ViewBag.ExamEnd = exam.ExamEndTime; List <PaperQuestion> paper = new List <PaperQuestion>(); paper = db.PaperQuestions.Where(x => x.ExamId == examid).OrderBy(x => x.NumberInPaper).ToList(); //ViewBag.PaperQuestions = paper; string username = User.Identity.GetUserName(); //string id = paper.First().ExamId; // we get the paperquestions for this exam in a list // List<PaperQuestion> paper = db.PaperQuestions.Where(x => x.ExamId == id).ToList(); //now we generate a list of QuestionId found in the list above IEnumerable <int> SpecificQuestions = new List <int>(from p in paper select p.QuestionId); //and we select those Questions that match the QuestionIds List <Question> questionList = new List <Question>(from q in db.Questions where SpecificQuestions.Contains(q.QuestionId) select q); //now we get the multiple choices we need for this exam List <MultipleChoice> multichoiceList = new List <MultipleChoice>(from m in db.MultipleChoices where SpecificQuestions.Contains(m.QuestionId) select m); ViewBag.MultiChoices = multichoiceList; ViewBag.Questions = questionList; //ViewBag.PaperQuestions = db.PaperQuestions.Where(x => x.ExamId == id).ToList(); //ViewBag.Questions = db.Questions.ToList(); //we get the StudentAnswers that concern us only string[] idSplit = examid.Split('-'); username = username + "-" + idSplit[0]; IEnumerable <string> specificPaperQuestions = from p in paper select p.PaperQuestionId; List <StudentAnswer> answerList = new List <StudentAnswer>(from q in db.StudentAnswers where specificPaperQuestions.Contains(q.PaperQuestionId) select q); List <StudentAnswer> specificAnswerList = answerList.Where(x => x.EnrollmentId == username).ToList(); ViewBag.Answers = specificAnswerList; ViewData["ExamId"] = examid; //now we get the subject string subjectid = (from q in questionList select q.SubjectId).FirstOrDefault(); ViewBag.Subject = subjectid; //return View(paper); return(paper); }
private void button1_Click(object sender, EventArgs e) { Admin adm = MyAdmin.Admin; Student stu = new Student(students[StudentsComboBox.SelectedIndex].Id, students[StudentsComboBox.SelectedIndex].Name); ExamSession session = new ExamSession(sessions[ExamSessionsComboBox.SelectedIndex].Id); SessionStudentAdminDAL.Add(session, adm, stu); }
private void AssignSessionForCourseBtn_Click(object sender, EventArgs e) { ComboboxItem cb = (ComboboxItem)sessionsComboBox.SelectedItem; ExamSession session = ExamSessionDAL.GetById((int)cb.Value);//el id ele rage3 mn el session ele et3amalaha create updateCourse(); CourseExamSessionAdminDAL.GenerateExamSessionForCourse(session, adm, course); }
public async Task <ActionResult> DeleteConfirmed(string id) { ExamSession examSession = await db.ExamSessions.FindAsync(id); db.ExamSessions.Remove(examSession); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public void BeginExam(ExamFileInfo examInfo) { ExamSession session = _uiManager.ShowExamConfigurationView(examInfo); if (session != null) { BeginExamSession(session); } OnExamCompleted?.Invoke(null, session == null ? ExamOutcome.NotStarted : ExamOutcome.Completed); }
public ActionResult ExamEndChange(string idd) { ExamSession examSession = new ExamSession(); examSession = db.ExamSessions.Find(idd); examSession.ExamEndTime = null; db.Entry(examSession).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Edit", "ExamSessions", new { id = idd })); }
private ExamSessionDto MapToDto(ExamSession examSession) { var examSessionDto = new ExamSessionDto { Id = examSession.Id, Description = examSession.Description, Name = examSession.Name, EndDate = examSession.EndDate, StartDate = examSession.StartDate, ExamSiteId = examSession.ExamSite.Id }; return(examSessionDto); }
// GET: ExamSessions/Details/5 public async Task <ActionResult> Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ExamSession examSession = await db.ExamSessions.FindAsync(id); if (examSession == null) { return(HttpNotFound()); } return(View(examSession)); }
public async Task <ActionResult> Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ExamSession examSession = await db.ExamSessions.FindAsync(id); if (examSession == null) { return(RedirectToAction("ExamManager", "Clerk")); } string user = User.Identity.GetUserId(); int?dept = (from u in db.Users where u.Id == user select u.DepartmentId).FirstOrDefault(); List <int> depts = new List <int>(from d in db.Departments where d.DepartmentId == dept || d.DepartmentParentId == dept select d.DepartmentId); if (!depts.Contains(examSession.RelatedSubject.DepartmentId)) { return(RedirectToAction("Management", "Dashboard")); } List <Subject> subjects = new List <Subject>(from s in db.Subjects where depts.Contains(s.RelatedDepartment.DepartmentId) select s); ViewBag.Start = examSession.ExamDateTime; var Locations = db.Locations.Select(x => x.Campus).Distinct().ToList(); ViewBag.SubjectId = new SelectList(subjects, "SubjectId", "SubjectName"); ViewBag.LocationId = new SelectList(Locations, examSession.LocationId); if (examSession.LocationId != null) { var LocationCall = db.Locations.Where(x => x.LocationId == examSession.LocationId).FirstOrDefault(); ViewBag.LocationCall = new string[] { LocationCall.Campus, LocationCall.Building, LocationCall.Floor, LocationCall.Block, LocationCall.Room }; } return(View(examSession)); }
public async Task <IActionResult> GetSession(int id) { if (id < 1) { return(BadRequest("Invalid exam id.")); } AppUser user = await _usermanager.GetUserAsync(User); var exam = _repos.Exams.GetWith(id, "Sessions"); if (exam == null) { return(NotFound("Exam record with that id does not exist.")); } var session = exam.Sessions .FirstOrDefault(x => x.StudentId == user.AccountId); if (session == null) { session = new ExamSession() { ExamId = exam.Id, StudentId = user.AccountId }; session = _repos.ExamSessions.Create(session); exam.Sessions.Add(session); exam = _repos.Exams.Update(exam); _repos.Commit(); } var examViewModel = _dataManager.GetExam(id); var examSession = new ExamSessionViewModel() { Id = session.Id, SessionId = session.SessionId, TotalQuestions = examViewModel.Questions.Count, TotalMarks = examViewModel.Questions.Sum(x => x.Marks), Exam = examViewModel }; return(Ok(examSession)); }
public static int Add(ExamSession session, Admin admin, Student student) { int result = 0; //string connection = @"Data Source=BASMA-HP\SQLEXPRESS;Initial Catalog=ExaminationSystems;Integrated Security=True"; SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(DBLayer.connection); SqlCommand sqlCommand = new SqlCommand(); sqlConnection.Open(); sqlCommand.CommandText = "insertExamSessionStudentAdmin"; sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@session", session.Id); sqlCommand.Parameters.AddWithValue("@stID", student.Id); sqlCommand.Parameters.AddWithValue("@adminID", admin.Id); sqlCommand.Connection = sqlConnection; result = sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); return(result); }
public static int GenerateExamSessionForCourse(ExamSession examSession, Admin adm, Course course) { int result = 0; string connection = @"Data Source=BASMA-HP\SQLEXPRESS;Initial Catalog=ExaminationSystems;Integrated Security=True"; SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(connection); SqlCommand sqlCommand = new SqlCommand(); sqlConnection.Open(); sqlCommand.CommandText = "insertCourse_ExamSession_Admin"; sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@courseID", course.Id); sqlCommand.Parameters.AddWithValue("@examSession", examSession.Id); sqlCommand.Parameters.AddWithValue("@adminID", adm.Id); sqlCommand.Connection = sqlConnection; result = sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); return(result); }
public static ExamSessionCollection SelectAll() { DataTable dt = DBLayer.ExecuteQuery("select * from ExamSession"); ExamSessionCollection result = new ExamSessionCollection(); for (int i = 0; i < dt.Rows.Count; i++) { Exam exam = new Exam(); Admin adm = new Admin(); int sessionID = Convert.ToInt32(dt.Rows[i]["session_ID"]); DateTime dateTime = Convert.ToDateTime(dt.Rows[i]["session_date"]); exam.Id = Convert.ToInt32(dt.Rows[i]["FK_ExamID"]); adm.Id = Convert.ToInt32(dt.Rows[i]["FK_AdminID"]); ExamSession session = new ExamSession(sessionID, dateTime, exam, adm); result.Add(session); } return(result); }
public static ExamSession GetById(int id) { DataTable dt = DBLayer.ExecuteQuery(string.Format("select * from ExamSession where session_ID = {0}", id)); ExamSession result = new ExamSession(); if (dt.Rows.Count > 0) { DateTime date = Convert.ToDateTime(dt.Rows[0]["session_date"]); Exam exam = new Exam(); exam.Id = Convert.ToInt32(dt.Rows[0]["FK_ExamID"]); Admin adm = new Admin(); adm.Id = Convert.ToInt32(dt.Rows[0]["FK_AdminID"]); result.Id = id; result.SessionDate = date; result.Exam = exam; result.Admin = adm; } return(result); }
private async Task <ExamSession> MapFromDto(ExamSessionDto examSessionDto) { var examSite = await _context.ExamSites .FirstOrDefaultAsync(e => e.Id == examSessionDto.ExamSiteId); if (examSite != null) { var examSession = new ExamSession { Id = examSessionDto.Id, Description = examSessionDto.Description, Name = examSessionDto.Name, EndDate = examSessionDto.EndDate, StartDate = examSessionDto.StartDate, ExamSite = examSite }; return(examSession); } return(null); }
public ActionResult Create(string id) { if (id == null) { return(RedirectToAction("ExamManager", "Clerk")); } IEnumerable <ExamSession> exam = new List <ExamSession>(from e in db.ExamSessions where e.ExamId == id select e); ExamSession specificExam = new ExamSession(); specificExam = (from e in db.ExamSessions where e.ExamId == id select e).SingleOrDefault(); ViewBag.Subject = specificExam.SubjectId; List <ApplicationUser> invigilators = new List <ApplicationUser>(from u in db.Users where u.Role == "Invigilator" select u); if (invigilators.Count == 0) { return(RedirectToAction("ExamManager", "Clerk")); } List <object> newList = new List <object>(); foreach (var member in invigilators) { newList.Add(new { Id = member.Id, FirstName = member.UserName + ": " + member.FirstName + " " + member.Surname }); } ViewBag.UserId = new SelectList(newList, "Id", "FirstName"); ViewBag.ExamId = new SelectList(exam, "ExamId", "SubjectId"); return(View()); }
// GET: Exam // GET: PaperQuestions public async Task <ActionResult> EditPapers(string subject) { string teacher = User.Identity.GetUserId(); //We get a list of only subjects for this tutor List <string> subjectNames = new List <string>(from t in db.Teachings.Where(x => x.ExaminerId == teacher) select t.SubjectId); List <Subject> subjects = new List <Subject>(from s in db.Subjects where subjectNames.Contains(s.SubjectId) select s); SetPaperViewModel viewmodel; if (subject == null) { viewmodel = new SetPaperViewModel() { Subjects = subjects }; ViewBag.Alert = ""; return(View(viewmodel)); } else if (subject == "") { viewmodel = new SetPaperViewModel() { Subjects = subjects }; ViewBag.Alert = "Please select subject from the dropdown!"; return(View(viewmodel)); } ExamSession examsession = (from e in db.ExamSessions where (e.SubjectId == subject && !e.FullyCorrected) select e) .SingleOrDefault(); string session; //if there is no session for this subject, a new ExamSession is Created. if (examsession == null) { ExamSession newExamSession = new ExamSession(); session = subject + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year; newExamSession.ExamId = session; newExamSession.SubjectId = subject; db.ExamSessions.Add(newExamSession); await db.SaveChangesAsync(); //regetting the examsession examsession = (from e in db.ExamSessions where (e.SubjectId == subject && !e.FullyCorrected) select e) .SingleOrDefault(); } else { session = examsession.ExamId; } //if the exam is in a day or less if (examsession.ExamDateTime != null && examsession.ExamDateTime.Value.DayOfYear - DateTime.Now.DayOfYear <= 1) { viewmodel = new SetPaperViewModel() { Subjects = subjects }; //we don't permit editting of the paper. ViewBag.Alert = "Changing of a Paper is not permitted 24 hours prior to an exam. Call the Administrator if necessary"; return(View(viewmodel)); } List <PaperQuestion> paperQuestions = new List <PaperQuestion>(from p in db.PaperQuestions orderby p.NumberInPaper where p.ExamId == session select p); List <int> questionsUsed = new List <int>(from p in db.PaperQuestions where p.ExamId == session select p.QuestionId); List <Question> questionList = new List <Question>(from q in db.Questions where q.SubjectId == subject && !questionsUsed.Contains(q.QuestionId) select q); //IList<byte> marks = new List<byte>(from p in paperQuestions select p.MarksAllocated); int total = 0; foreach (PaperQuestion p in paperQuestions) { total = total + (int)p.MarksAllocated; } viewmodel = new SetPaperViewModel { Subject = subject, Subjects = subjects, Session = session, AvailableQuestions = questionList, Included = paperQuestions, Mark = total }; ViewBag.Alert = ""; return(View(viewmodel)); }
public ExamSessionModel(ExamSession model) : base(model) { StartTime = model.StartTime; }
public void ShowDialog(ExamSession session) { ShowDialog(); }
public void ShowExamShell(ExamSession session) { _examShellView.ShowDialog(session); }
private void BeginExamSession(ExamSession session) { _uiManager.ShowExamShell(session); }
public Task <ExamSessionFormVM> ReturnPopulatedExamSessionForm(ExamSession examSession) { var examSessionDto = MapToDto(examSession); return(ReturnPopulatedExamSessionFormDto(examSessionDto)); }
public async Task <ActionResult> Index(string AccessCode, string examid, string imagename) { string username = User.Identity.GetUserId(); if (examid == null) { RedirectToAction("Index", "Home"); } //we get the subject code string[] idSplit = examid.Split('-'); if (AccessCode != null) { Log log = new Log(); log.Activity = "Attempted Exam Access Code for ExamSession: " + examid; log.WhoId = username; log.When = DateTime.Now; db.Logs.AddOrUpdate(log); await db.SaveChangesAsync(); } ExamSession exam = new ExamSession(); exam = (from e in db.ExamSessions where e.ExamId == examid select e).FirstOrDefault(); Enrollment enroller = new Enrollment(); string enrollerid = User.Identity.GetUserName() + "-" + idSplit[0]; enroller = (from e in db.Enrollments where e.EnrollmentId == enrollerid select e).FirstOrDefault(); if (imagename == "") { ViewData["ExamId"] = examid; ViewData["Error"] = "You have not submitted an image"; return(View()); } if (enroller == null) { ViewData["ExamId"] = examid; ViewData["Error"] = "There was an error"; return(View()); } if (exam == null) { ViewData["ExamId"] = examid; ViewData["Error"] = "Exam not found"; return(View()); } if (DateTime.Now.Minute > exam.CodeIssueDateTime.Value.Minute + 6 || (DateTime.Now.Hour > exam.CodeIssueDateTime.Value.Hour)) { ViewData["ExamId"] = examid; ViewData["Error"] = "The last Access Code has expired. " + "Ask the Invigilator for a new one"; return(View()); } else { if (AccessCode != exam.AccessCode) { ViewData["ExamId"] = examid; ViewData["Error"] = "This code is not correct"; return(View()); } } ViewData["ExamId"] = examid; ViewData["AccessCode"] = AccessCode; //now we get the subject ViewBag.Subject = exam.SubjectId; if (AccessCode == exam.AccessCode) { //getting the amount of pictures he already took //stick it to the user to get enrollment string enrollment = User.Identity.GetUserName() + "-" + idSplit[0]; int imageAmount = db.Shots.Where(x => x.EnrollmentId == enrollment).Count() + 1; //set the file name string imageData = enrollment + "_" + imageAmount; //creating the file itself string[] trimmedImageName = imagename.Split(','); byte[] contents = Convert.FromBase64String(trimmedImageName[1]); System.IO.File.WriteAllBytes(Server.MapPath("/Captures/" + imageData + ".png"), contents); //placing location on database var UserImageDetails = new Shot { EnrollmentId = enrollment, ImageTitle = imageData, ImageLocation = "/Captures/" + imageData + ".png", ShotTiming = DateTime.Now }; //BEGIN we mark the student as present Enrollment EnrollmentToChange = db.Enrollments.Find(enrollment); EnrollmentToChange.FinalAssessment = Enrollment.Assessment.Present; EnrollmentToChange.SessionStatus = Enrollment.Status.Unchecked; //END we mark the student as present db.Shots.Add(UserImageDetails); db.SaveChanges(); ViewData["ExamId"] = examid; ViewData["Error"] = ""; //return RedirectToAction("Index","Snap",new { examid=exam.ExamId} ); //redirects to a get //return RedirectToAction("ExamPage", new { examid=exam.ExamId } ); List <PaperQuestion> paper = ExamPage(examid); return(View(paper)); } return(View()); }