public ActionResult CreateGroup()
        {
            if (User.Identity.GetAccountType().Equals("Student"))
            {
                return(RedirectToAction("UserHome", controllerName: "User"));
            }
            string GroupID = RandomCode.RandomString(6);

            return(View());
        }
        public ActionResult JoinGroup(JoinGroupModels models)
        {
            var checkclassid =
                from c in _context.UserClass
                where c.ClassID == models.ClassID
                select new
            {
                Classid = c.ClassID
            };

            if (!checkclassid.Any())
            {
                ModelState.AddModelError("JoinDupGroupNotExist", errorMessage: "Class Doesn't Exist. Please enter new Class ID");
                return(View(models));
            }
            models.StudentID   = User.Identity.GetUserId();
            models.classdetail = RandomCode.RandomString(10);
            UserInClass iin = new UserInClass()
            {
                StudentID = models.StudentID, ClassID = models.ClassID
            };

            iin.classdetail = models.classdetail;
            var query =
                from dup in _context.UserInClasses
                where (dup.ClassID == models.ClassID && dup.StudentID == models.StudentID)
                select new
            {
                dupname = dup.StudentID
            };

            foreach (var i in query)
            {
                if (i.dupname == models.StudentID)
                {
                    ModelState.AddModelError("JoinDupGroupError", errorMessage: "You Already Join This Group");
                    return(View(models));
                }
            }

            try
            {
            }
            catch (Exception)
            {
                ModelState.AddModelError("JoinGroupError", errorMessage: "Cannot Join Group At This Time");
                return(View(models));
            }
            _context.UserInClasses.Add(iin);
            _context.SaveChanges();
            return(RedirectToAction("StudentGroupView"));
        }
 public ActionResult CreateGroup(CreateGroupModels models)
 {
     if (User.Identity.GetAccountType().Equals("Student"))
     {
         return(RedirectToAction("UserHome", controllerName: "User"));
     }
     models.TeacherID = User.Identity.GetUserId();
     models.ClassID   = RandomCode.RandomString(6);
     try
     {
         _context.UserClass.Add(new UserClass()
         {
             ClassID = models.ClassID, ClassName = models.ClassName, SubjectName = models.SubjectName, TeacherID = models.TeacherID, Color = models.Color
         });
         _context.SaveChanges();
     }
     catch (Exception)
     {
         ModelState.AddModelError("Error", errorMessage: "Cannot Create Class");
         return(View(models));
     }
     return(RedirectToAction("TeacherGroupDetailView", new { ClassID = models.ClassID }));
 }