Ejemplo n.º 1
0
        public ActionResult SaveNewGroup(List<string> allStudentPhones, long activeExpId, long roomId)
        {
            // add group to activeExp
            List<StudentData> students = new List<StudentData>();
            bool allAvailable = true;
            StudentData sd;
            string errMsg = "";

            foreach (string currentStudentPhone in allStudentPhones)
            {
                sd = rsContext.getStudent(currentStudentPhone, roomId);
                if (sd == null || !sd.isAvailable())
                {
                    allAvailable = false;
                    if (sd == null)
                    {
                        errMsg = Resources.Resources.StudentErrorMsg1;
                    }
                    else
                    {
                        errMsg = Resources.Resources.StudentErrorMsg2;
                    }
                }
                students.Add(sd);
            }

            if (!allAvailable)
            {
                TempData["StudentPhone"] = allStudentPhones.ElementAt(0);
                TempData["ActiveExpID"] = activeExpId;
                TempData["StudentRoom"] = roomId;
                TempData["errorMessage"] = errMsg;
                return PartialView("CreateGroupForm");
            }

            GroupData groupData = new GroupData(activeExpId, students);
            rsContext.addGroup(groupData);

            foreach (StudentData currentSD in students)
            {
                currentSD.GroupID = groupData.GroupID;
            }

            string studentPhone = allStudentPhones[0];
            ActiveExperimentData aeData = rsContext.getActiveExperiment(activeExpId);
            aeData.IncrementCreatedGroupsCounter();
            rsContext.SaveChanges();
            return RedirectToAction("Experiment", new { expId = aeData.ExpID, studentPhone = studentPhone, studentRoom = roomId, currActivityIndex = 0 });
        }