// // GET: /SubjectRegistration/Details/5 public ActionResult Details(int id) { //msContext SubjectRegistration theSubReg = work.SubjectRegistrationRepository.GetByID(id); return(View(theSubReg)); }
// // GET: /SubjectRegistration/Create public ActionResult Create() { SubRegistrationViewModel model = new SubRegistrationViewModel(); SubjectRegistration thesubReg = new SubjectRegistration(); List <Subject> theSubjects = work.SubjectRepository.Get().OrderBy(a => a.Name).ToList(); model.Subjects = theSubjects; model.SubjectRegistration = thesubReg; Dictionary <string, string> theDic = new Dictionary <string, string>(); List <SelectListItem> theItem = new List <SelectListItem>(); List <Subject> theSub = work.SubjectRepository.Get().OrderBy(a => a.Name).ToList(); foreach (var subject in theSub) { theItem.Add(new SelectListItem() { Text = subject.Name, Value = subject.Name }); } // theItem.Add(new SelectListItem() { Text = "PRIMART 1A", Value = "PRIMART 1A" }); ViewBag.Subjects = theItem; ViewBag.Subject = theSub; return(View(model)); }
/// <inheritdoc /> public void RegisterSubject <T>(ulong objectId, T subject) where T : class { var registration = new SubjectRegistration <T>(objectId, subject); // TODO: This method is missing some sort of verification of the given subject type. // Currently, verification only happens when we are connected to an endpoint. // This is bad because a user of this class only noticies that stuff goes wrong // because no other endpoint can establish connections with this endpoint. var stopwatch = Stopwatch.StartNew(); lock (_syncRoot) { _subjects.Add(objectId, registration); foreach (var endPoint in _internalEndPoints) { registration.RegisterSubjectWith(endPoint); } } stopwatch.Stop(); Log.DebugFormat("{0}: Created new servant (#{1}) '{2}' implementing '{3}', took {4}ms", _name, objectId, subject, typeof(T), stopwatch.ElapsedMilliseconds); }
//[HttpPost] //public ActionResult Edit(SubjectRegistration model, string[] selectedCourses) //{ // try // { // // TODO: Add update logic here // List<Subject> theSubjects = new List<Subject>(); // List<Subject> theSubjects2 = new List<Subject>(); // foreach (var sub in selectedCourses) // { // int theIntValue = Convert.ToInt32(sub); // theSubjects2 = work.SubjectRepository.Get(a => a.SubjectID == theIntValue).ToList(); // theSubjects.Add(theSubjects2[0]); // } // model.Subjects = theSubjects; // work.SubjectRegistrationRepository.Update(model); // work.Save(); // return RedirectToAction("Index"); // } // catch // { // return View(); // } //} private void UpdateInstructorCourses(string[] selectedCourses, SubjectRegistration instructorToUpdate) { if (selectedCourses == null) { instructorToUpdate.Subjects = new List <Subject>(); return; } var selectedCoursesHS = new HashSet <string>(selectedCourses); var instructorCourses = new HashSet <int> (instructorToUpdate.Subjects.Select(c => c.SubjectID)); foreach (var course in work.SubjectRepository.Get().ToList()) { if (selectedCoursesHS.Contains(course.SubjectID.ToString())) { if (!instructorCourses.Contains(course.SubjectID)) { instructorToUpdate.Subjects.Add(course); } } else { if (instructorCourses.Contains(course.SubjectID)) { instructorToUpdate.Subjects.Remove(course); } } } }
public async Task <ActionResult> Edit([Bind(Include = "Id,StudentId,ClassName,TermName,SessionName,SubjectName")] SubjectRegistration model) { if (ModelState.IsValid) { var studentName = Db.Students.Where(x => x.StudentId.Equals(model.StudentId)) .Select(s => s.FullName) .FirstOrDefault(); var subjectRegistration = new SubjectRegistration() { StudentId = model.StudentId, StudentName = studentName, //ClassName = model.ClassName, //TermName = model.TermName, //SessionName = model.SessionName, SubjectId = model.SubjectId, SchoolId = userSchool }; Db.Entry(subjectRegistration).State = EntityState.Modified; await Db.SaveChangesAsync(); TempData["UserMessage"] = "Subject Registration Updated Successfully."; TempData["Title"] = "Success."; return(RedirectToAction("Index")); } //ViewBag.SessionName = new SelectList(_query.SessionList(), "SessionName", "SessionName"); //ViewBag.ClassName = new SelectList(await _query.ClassListAsync(userSchool), "FullClassName", "FullClassName"); //ViewBag.TermName = new SelectList(_query.TermList(), "TermName", "TermName"); ViewBag.StudentId = new SelectList(await _query.StudentListAsync(userSchool), "StudentID", "FullName"); ViewBag.SubjectId = new MultiSelectList(await _query.SubjectListAsync(userSchool), "SubjectId", "SubjectName"); return(View(model)); }
// // GET: /SubjectRegistration/Edit/5 public ActionResult Edit(int id) { SubjectRegistration theSubReg = work.SubjectRegistrationRepository.GetByID(id); PopulateAssignedSubjectData(theSubReg); return(View(theSubReg)); // return View(); }
public ActionResult Delete(SubjectRegistration model) { try { // TODO: Add delete logic here work.SubjectRegistrationRepository.Delete(model); work.Save(); return(RedirectToAction("Index")); } catch { return(View()); } }
private void PopulateAssignedSubjectData(SubjectRegistration instructor) { var allCourses = work.SubjectRepository.Get(); //db.Courses; var instructorCourses = new HashSet <int>(instructor.Subjects.Select(c => c.SubjectID)); var viewModel = new List <AssignedSubjectData>(); foreach (var course in allCourses) { viewModel.Add(new AssignedSubjectData { SubjectID = course.SubjectID, Name = course.Name, Assigned = instructorCourses.Contains(course.SubjectID) }); } ViewBag.Courses = viewModel; }
public ActionResult Edit(SubjectRegistration model, string[] selectedCourses) { List <SubjectRegistration> theReg = work.SubjectRegistrationRepository.Get(a => a.Level.Equals(model.Level)).ToList(); SubjectRegistration theRegi = theReg[0]; SubjectRegistration SubjectRegistrationToUpdate = work.SubjectRegistrationRepository.GetByID(theRegi.SubjectRegistrationID); // SubjectRegistration SubjectRegistrationToUpdate = theReg[0]; //var SubjectRegistrationToUpdate = db.SubjectRegistrations // .Include("Subjects") // .Where(i => i.Level == model.Level) // .Single(); if (TryUpdateModel(SubjectRegistrationToUpdate, "", null, new string[] { "Courses" })) { try { //if (String.IsNullOrWhiteSpace(instructorToUpdate.OfficeAssignment.Location)) //{ // instructorToUpdate.OfficeAssignment = null; //} // work.SubjectRegistrationRepository.Get(a=>a.Level.Equals(SubjectRegistrationToUpdate.Level)) UpdateInstructorCourses(selectedCourses, SubjectRegistrationToUpdate); work.SubjectRegistrationRepository.Update(SubjectRegistrationToUpdate); work.Save(); // db. Update(SubjectRegistrationToUpdate); // db.Save(); // db.Entry(SubjectRegistrationToUpdate).State = EntityState.Modified; // db.SaveChanges(); return(RedirectToAction("Index")); } catch (DataException) { //Log the error (add a variable name after DataException) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } } // PopulateAssignedCourseData(SubjectRegistrationToUpdate); // return View(instructorToUpdate); return(View("Index")); }
public ActionResult Create(SubRegistrationViewModel model, string[] SubjectRegistration) { try { if (SubjectRegistration == null || model.Level == null) { // SubRegistrationViewModel model = new SubRegistrationViewModel(); SubjectRegistration thesubReg = new SubjectRegistration(); List <Subject> theSubjects = work.SubjectRepository.Get().OrderBy(a => a.Name).ToList(); model.Subjects = theSubjects; model.SubjectRegistration = thesubReg; Dictionary <string, string> theDic = new Dictionary <string, string>(); List <SelectListItem> theItem = new List <SelectListItem>(); List <Subject> theSub = work.SubjectRepository.Get().OrderBy(a => a.Name).ToList(); foreach (var subject in theSub) { theItem.Add(new SelectListItem() { Text = subject.Name, Value = subject.Name }); } // theItem.Add(new SelectListItem() { Text = "PRIMART 1A", Value = "PRIMART 1A" }); ViewBag.Subjects = theItem; ViewBag.Subject = theSub; ModelState.AddModelError("", "Select at least one Subject to a given Class"); ////// return(View(model)); } else { List <SubjectRegistration> theRegSub = work.SubjectRegistrationRepository.Get(a => a.Level == model.Level).ToList(); if (theRegSub.Count > 0) { // SubRegistrationViewModel model = new SubRegistrationViewModel(); SubjectRegistration thesubReg = new SubjectRegistration(); List <Subject> theSubjects = work.SubjectRepository.Get().OrderBy(a => a.Name).ToList(); model.Subjects = theSubjects; model.SubjectRegistration = thesubReg; Dictionary <string, string> theDic = new Dictionary <string, string>(); List <SelectListItem> theItem = new List <SelectListItem>(); List <Subject> theSub = work.SubjectRepository.Get().OrderBy(a => a.Name).ToList(); foreach (var subject in theSub) { theItem.Add(new SelectListItem() { Text = subject.Name, Value = subject.Name }); } // theItem.Add(new SelectListItem() { Text = "PRIMART 1A", Value = "PRIMART 1A" }); ViewBag.Subjects = theItem; ViewBag.Subject = theSub; ModelState.AddModelError("", "Class Subjects for Selected Class has been Created Earlier"); return(View(model)); } // TODO: Add insert logic here List <Subject> theSubjects4 = new List <Subject>(); List <Subject> theSubjects2 = new List <Subject>(); foreach (var sub in SubjectRegistration) { theSubjects2 = work.SubjectRepository.Get(a => a.Name.Equals(sub)).ToList(); theSubjects4.Add(theSubjects2[0]); } SubjectRegistration theRealSub = new SubjectRegistration(); theRealSub.Level = model.Level; theRealSub.Subjects = theSubjects4; work.SubjectRegistrationRepository.Insert(theRealSub); work.Save(); return(RedirectToAction("Index")); } } catch { return(View()); } }
// // GET: /SubjectRegistration/Delete/5 public ActionResult Delete(int id) { SubjectRegistration theRegistrations = work.SubjectRegistrationRepository.GetByID(id); return(View(theRegistrations)); }
public async Task <ActionResult> Create([Bind(Include = "Id,StudentId,ClassName,TermName,SessionName,SubjectId")] SubjectRegistrationVm model) { if (ModelState.IsValid) { int counter = 0; string theClass = string.Empty; foreach (var subject in model.SubjectId) { var studentName = Db.Students.Where(x => x.StudentId.Equals(model.StudentId)) .Select(s => s.FullName) .FirstOrDefault(); var countFromDb = Db.SubjectRegistrations.Count(x => x.StudentId.Equals(model.StudentId) && x.SubjectId.Equals(subject)); // x.ClassName.Equals(model.ClassName) //&& x.TermName.Equals(model.TermName.ToString()) //&& x.SessionName.Equals(model.SessionName) //&& ); // var countFromDb = CA.Count(); if (countFromDb >= 1) { TempData["UserMessage"] = $"Admin have already assigned {subject} subject to this {studentName} Student"; TempData["Title"] = "Error."; //ViewBag.SessionName = new SelectList(_query.SessionList(), "SessionName", "SessionName"); //ViewBag.ClassName = new SelectList(await _query.ClassListAsync(userSchool), "FullClassName", "FullClassName"); //ViewBag.TermName = new SelectList(_query.TermList(), "TermName", "TermName"); ViewBag.StudentId = new SelectList(await _query.StudentListAsync(userSchool), "StudentID", "FullName"); ViewBag.SubjectId = new MultiSelectList(await _query.SubjectListAsync(userSchool), "SubjectId", "SubjectName"); return(View(model)); } var mySubject = new SubjectRegistration() { StudentId = model.StudentId, StudentName = studentName, //ClassName = model.ClassName, //TermName = model.TermName, //SessionName = model.SessionName, SubjectId = subject, SchoolId = userSchool }; Db.SubjectRegistrations.Add(mySubject); counter += 1; theClass = studentName; } await Db.SaveChangesAsync(); TempData["UserMessage"] = $" You have Assigned {counter} Subject(s) to {theClass} Successfully."; TempData["Title"] = "Success."; return(RedirectToAction("Index")); } //ViewBag.SessionName = new SelectList(_query.SessionList(), "SessionName", "SessionName"); //ViewBag.ClassName = new SelectList(await _query.ClassListAsync(userSchool), "FullClassName", "FullClassName"); //ViewBag.TermName = new SelectList(_query.TermList(), "TermName", "TermName"); ViewBag.StudentId = new SelectList(await _query.StudentListAsync(userSchool), "StudentID", "FullName"); ViewBag.SubjectId = new MultiSelectList(await _query.SubjectListAsync(userSchool), "SubjectId", "SubjectName"); return(View(model)); }