public IActionResult addStudentBatch(studentBatchViewModel model)
        {
            StudentInBatch studentInBatch = new StudentInBatch()
            {
                Student_Id = int.Parse(model.selectedStudent),
                Batch_Id   = int.Parse(model.selectedBatch)
            };

            _studentBatchRepo.AddStudentInBatch(studentInBatch);
            return(RedirectToAction("Index"));
        }
        public IActionResult addStudentBatch()
        {
            List <Student>        studentlist           = _studentRepo.GetAllStudent().ToList();
            List <Batch>          batches               = _batchRepo.GetAllBatch().ToList();
            studentBatchViewModel studentBatchViewModel = new studentBatchViewModel()
            {
                studentList = studentlist,
                batchList   = batches
            };

            return(View(studentBatchViewModel));
        }
示例#3
0
        public IActionResult addStudentBatch(studentBatchViewModel model)
        {
            //get the batchID and the studentID from the model
            //int batchID = int.Parse(model.selectedBatch);
            int studentID = int.Parse(model.selectedStudent);

            //int bid = model.Id;

            if (ModelState.IsValid)
            {
                //check if there are duplicates
                var studentinbatch = _studentBatchRepo.GetAllStudentInBatchs().Where(c => c.Batch_Id == model.Id && c.Student_Id == studentID).FirstOrDefault();
                if (studentinbatch == null)
                {
                    StudentInBatch studentInBatch = new StudentInBatch()
                    {
                        Student_Id     = studentID,
                        Batch_Id       = model.Id,
                        Student_Status = model.studentStaus,
                        Grade          = model.studentGrade
                    };
                    _studentBatchRepo.AddStudentInBatch(studentInBatch);

                    //add a program to this Batch
                    //Programme program = new Programme()
                    //{
                    //    BatchId = batchID,
                    //    Program_Name = model.programType,
                    //    Duration = model.duration
                    //};
                    //_program.AddProgramme(program);
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError("duplicate keys", "Already asigned");
                List <Student>        studentlist           = _studentRepo.GetAllStudent().ToList();
                List <Batch>          batches               = _batchRepo.GetAllBatch().ToList();
                studentBatchViewModel studentBatchViewModel = new studentBatchViewModel()
                {
                    studentList = studentlist,
                    batchList   = batches
                };
                return(View(studentBatchViewModel));
            }
            return(View(model));
        }