public ActionResult Add(DateTime start, DateTime end, string classcode) { Teacher t = UserBinding.getTeacher(User.Identity.GetUserId()); //TODO clean parameters if (t == null) { return(RedirectToAction("Index", "Home")); } if (ClassroomBinding.GetClassroomFromCode(classcode)?.classID != null) { ViewBag.ErrorMessage = "Error: please enter a unique class code."; return(View()); } var classroom = new Classroom { classID = ClassroomBinding.GenerateClassId(), semesterStart = start, semesterEnd = end, classCode = classcode, teacherID = t.TeacherID }; ClassroomBinding.SaveRoom(classroom); return(RedirectToAction("Index", "Home")); }
public ActionResult Index(DateTime date) { Student s = UserBinding.getStudent(User.Identity.GetUserId()); UserBinding.RequestPrize(s.StudentID, date); return(View()); }
// POST api/values public ResponseBinding Post([FromBody] UserBinding model) { if (!ModelState.IsValid) { return(new ResponseBinding { HttpStatusCode = 422, Message = "Todos los campos son necesarios", Status = false }); } var user = new User { Name = model.Name, Password = model.Password, Username = model.Username, }; this.Context.Users.Add(user); this.Context.SaveChanges(); return(new ResponseBinding { Content = user, Message = "Usuario creado con exito", HttpStatusCode = (int)HttpStatusCode.OK, Status = true }); }
// PUT api/values/5 public ResponseBinding Put(string id, [FromBody] UserBinding model) { var guid = Guid.Parse(id); var user = this.Context.Users.Find(guid); if (user == null) { return(new ResponseBinding { HttpStatusCode = (int)HttpStatusCode.OK, Message = $"Usuario con id ({id}) no encontrado", Status = false }); } //user.Username = model.Username; user.Name = model.Name; user.Password = model.Password; this.Context.Entry(user).State = System.Data.Entity.EntityState.Modified; this.Context.SaveChanges(); return(new ResponseBinding { Content = user, HttpStatusCode = (int)HttpStatusCode.OK, Message = "Usuario Actualizado con exito", Status = true }); }
public ActionResult Join(string classCode) { var user = User.Identity.GetUserId(); Classroom cr = ClassroomBinding.GetClassroomFromCode(classCode); if (user == null || cr == null || classCode == null) { ViewBag.ErrorMessage = "Error: There was an issue joining a classroom."; return(View()); } UserBinding.JoinClass(user, classCode); return(View()); }
public ActionResult Index() { if (Request.IsAuthenticated) { var AspNetUser = UserManager.FindById(User.Identity.GetUserId()); IndexViewModel model = new IndexViewModel { userClassroomRole = AspNetUser.ClassroomRole }; if (AspNetUser.ClassroomRole == "Student") { Student studentUser = UserBinding.getStudent(AspNetUser.Id); if (studentUser == null) { return(View(new IndexViewModel())); } model.userfname = studentUser.studentFirst; if (studentUser.classID == null) { model.userClassrooms = null; return(View(model)); } model.userClassrooms = new List <Classroom>(); model.userClassrooms.Add(ClassroomBinding.GetClassroomFromID(studentUser.classID)); } else if (AspNetUser.ClassroomRole == "Parent") { Parent parentUser = UserBinding.getParent(AspNetUser.Id); model.userfname = parentUser.parentFirst; } else if (AspNetUser.ClassroomRole == "Teacher") { Teacher teacherUser = UserBinding.getTeacher(AspNetUser.Id); if (teacherUser == null) { //TODO add log? return(View(new IndexViewModel())); } model.userfname = teacherUser.teacherFirst; model.userlname = teacherUser.teacherLast; model.userClassrooms = UserBinding.getTeacherClassrooms(teacherUser.TeacherID); } return(View(model)); } return(View()); }
public ActionResult Index(string classcode) { Teacher t = UserBinding.getTeacher(User.Identity.GetUserId()); Classroom cr = ClassroomBinding.GetClassroomFromCode(classcode); if (cr == null || t == null || classcode == null) { //TODO add viewbag error? return(RedirectToAction("Index", "Home")); } ClassroomIndexViewModel model = new ClassroomIndexViewModel(); model.Classroom = cr; model.Teacher = t; model.Students = cr.Student.ToList(); return(View(model)); }
public ActionResult Add(NewBehaviorViewModel model, FormCollection form) { if (!ModelState.IsValid || model.DatePerformed == null || model.BehaviorTypePerformedID == null) { return(RedirectToAction("Home", "Index")); } Student student = UserBinding.getStudent(model.StudentUserID); if (student.classID == null) { return(RedirectToAction("Home", "Index")); } BehaviorType bt = ClassroomBinding.GetBehaviorType((decimal)student.classID, Convert.ToDecimal(model.BehaviorTypePerformedID)); UserBinding.AddBehaviorToStudent(student, bt, model.DatePerformed); return(RedirectToAction("Index", "Classroom", new { classcode = ClassroomBinding.GetClassroomFromID(student.classID).classCode })); }
public async Task <ActionResult> Index(ManageMessageId?message) { ViewBag.StatusMessage = message == ManageMessageId.Error ? "An error has occurred." : ""; var AspNetUser = UserManager.FindById(User.Identity.GetUserId()); var model = new IndexViewModel { userClassroomRole = AspNetUser.ClassroomRole }; if (AspNetUser.ClassroomRole == "Student") { Student studentUser = UserBinding.getStudent(AspNetUser.Id); if (studentUser == null) { studentUser = new Student(); } model.userfname = studentUser.studentFirst; } else if (AspNetUser.ClassroomRole == "Parent") { Parent parentUser = UserBinding.getParent(AspNetUser.Id); //TODO null check model.userfname = parentUser.parentFirst; } else if (AspNetUser.ClassroomRole == "Teacher") { Teacher teacherUser = UserBinding.getTeacher(AspNetUser.Id); if (teacherUser == null) { //TODO add log? return(View(new IndexViewModel())); } else { model.userfname = teacherUser.teacherFirst; model.userlname = teacherUser.teacherLast; } } return(View(model)); }
public ActionResult Index(string role, string fname, string lname) { if (role != null) { if (role == "Student") { var student = UserBinding.getStudent(User.Identity.GetUserId()); if (student != null) { student.studentFirst = fname; UserBinding.SaveStudent(student); } else { var newstudent = new Student { StudentID = UserBinding.GenerateStudentId(), studentFirst = fname, UserID = User.Identity.GetUserId(), studentUsername = User.Identity.GetUserName() }; UserBinding.SaveStudent(newstudent); } } else if (role == "Teacher") { var teacher = UserBinding.getTeacher(User.Identity.GetUserId()); if (teacher != null) { teacher.teacherFirst = fname; teacher.teacherLast = lname; UserBinding.SaveTeacher(teacher); } else { var newteacher = new Teacher { TeacherID = UserBinding.GenerateTeacherId(), teacherFirst = fname, teacherLast = lname, UserID = User.Identity.GetUserId(), teacherUsername = User.Identity.GetUserName() }; UserBinding.SaveTeacher(newteacher); } } else if (role == "Parent") { var parent = new Parent { parentID = UserBinding.GenerateParentId(), parentFirst = fname, UserID = User.Identity.GetUserId(), parentUsername = User.Identity.GetUserName() }; UserBinding.SaveParent(parent); } //get logged in user from browser context ApplicationUser user = UserManager.FindById(User.Identity.GetUserId()); user.ClassroomRole = role; UserManager.Update(user); } var vmodel = new IndexViewModel { userClassroomRole = role }; return(View(vmodel)); }