public ActionResult LeaveTeam(int?Id) { //Get the course that containing the team int CourseId = db.Teams.Where(x => x.Id == Id).Select(x => x.CourseId).FirstOrDefault(); var UserId = User.Identity.GetUserId(); var id = db.StudentsInTeams.Where(x => x.TeamId == Id && x.StudentId == UserId).Select(x => x.Id).FirstOrDefault(); StudentsInTeams StudentsInTeams = db.StudentsInTeams.Find(id); db.StudentsInTeams.Remove(StudentsInTeams); db.SaveChanges(); return(RedirectToAction("MyTeams/" + CourseId)); }
public ActionResult AcceptRequest(int id) { var UserId = User.Identity.GetUserId(); StudentsInTeams StudentsInTeams = new StudentsInTeams(); TeamRequests Request = db.TeamRequests.SingleOrDefault(x => x.Id == id); StudentsInTeams.TeamId = Request.TeamId; StudentsInTeams.StudentId = UserId; Request.Accept = true; db.StudentsInTeams.Add(StudentsInTeams); db.SaveChanges(); return(RedirectToAction("UsersInTeams/" + Request.TeamId, "Teams")); }
public ActionResult Create(Team Teams, int id) { var UserId = User.Identity.GetUserId(); StudentsInTeams StudentsInTeams = new StudentsInTeams(); if (ModelState.IsValid) { Teams.StudentId = UserId; Teams.CourseId = id; StudentsInTeams.StudentId = UserId; StudentsInTeams.TeamId = Teams.Id; db.Teams.Add(Teams); db.StudentsInTeams.Add(StudentsInTeams); db.SaveChanges(); return(RedirectToAction("MyTeams/" + id)); } return(View(Teams)); }
public ActionResult AddToTeam(StudentsInTeams StudentsInTeams, int id, int StudentId) { var PersonalInformation = db.PersonalInformations.Where(x => x.StudentId == StudentId).FirstOrDefault <PersonalInformation>(); var UserId = User.Identity.GetUserId(); bool hasValue; if (PersonalInformation == null) { hasValue = false; } else { hasValue = true; } //Get the course that containing the team int CourseId = db.Teams.Where(x => x.Id == id).Select(x => x.CourseId).FirstOrDefault(); //students registered course var students = db.Enrollment.Where(x => x.CoursesId == CourseId).Select(x => x.StudentId).ToList(); //Teams in the course var Teams = db.Teams.Where(x => x.CourseId == CourseId).Select(x => x.Id).ToList(); //StudentsInTeams in the course var StudentsInTeam = db.StudentsInTeams.Where(x => Teams.Contains(x.TeamId)).Select(x => x.StudentId).ToList(); //Get num of students in the team int studentsInTeam = db.StudentsInTeams.Where(x => x.TeamId == id).Count(); //Get the team limit int GroupNum = db.Courses.Where(x => x.Id == CourseId).Select(x => x.GroupNum).FirstOrDefault(); //check the team limit if (studentsInTeam == GroupNum) { ModelState.AddModelError("TeamLimit", "this team is complite"); } //check if this student not registered in the course else if (!hasValue || !students.Contains(PersonalInformation.UserId)) { ModelState.AddModelError("IsStudentRegistered", "this student not registered in the course"); } //check if this student is in team else if (StudentsInTeam.Contains(PersonalInformation.UserId)) { ModelState.AddModelError("IsInTeam", "this student is in team"); } TeamRequests TeamRequests = new TeamRequests(); if (ModelState.IsValid) { TeamRequests.TeamId = id; TeamRequests.FromId = UserId; TeamRequests.Date = DateTime.Now; TeamRequests.ToId = PersonalInformation.UserId; TeamRequests.Accept = false; db.TeamRequests.Add(TeamRequests); db.SaveChanges(); return(RedirectToAction("MYTeams/" + id)); } return(View(StudentsInTeams)); }