Esempio n. 1
0
        public static string NewBatchFinalRegister(Batch bat, Batch_Subjects_Parts bps, IEnumerable <string> subj)
        {
            List <Batch_Subjects_Parts> assignSub = new List <Batch_Subjects_Parts>();

            try
            {
                rc.Batches.Add(bat);
                rc.SaveChanges();
                //int bpsID = GetBatchSubjPart();
                var getRelatedSubject = rc.Batch_Subjects_Parts.Where(s => subj.Contains(s.SubjectID.ToString())).ToList();

                foreach (var item in getRelatedSubject)
                {
                    assignSub.Add(new Batch_Subjects_Parts
                    {
                        BatchName = item.BatchName,
                        Part      = item.Part,
                        Part1     = item.Part1,
                        SubjectID = item.SubjectID,
                        ID        = Guid.NewGuid()
                    });
                    //bpsID++;
                }
                foreach (var item in assignSub)
                {
                    rc.Batch_Subjects_Parts.Add(item);
                }
                rc.SaveChanges();
                return("Successfully Record Added");
            }
            catch (Exception e)
            {
                return("Unable to Register Student" + " " + e.Message);
            }
        }
Esempio n. 2
0
        //On New Subject Assignment to Batch Assign All the Students that Subject
        public static string AddBatch_Subj_PartRec(Guid degree, string batch, Guid section, Guid subjects, int part
                                                   , List <Registeration> studentsSpecificToABatch)
        {
            using (TransactionScope t = new TransactionScope())
            {
                try
                {
                    //int subjID = int.Parse(subjects);
                    //int sectionID = int.Parse(section);
                    //int Part = int.Parse(part);
                    //int degID = int.Parse(degree);
                    var getDegreeName  = rc.Degree_Program.Where(s => s.ProgramID == degree).Select(s => s.Degree_ProgramName).FirstOrDefault();
                    var getSectionName = rc.Sections.Where(s => s.SectionID == section).Select(s => s.SectionName).FirstOrDefault();
                    var getSubjName    = rc.Subjects.Where(s => s.SubjectID == subjects).Select(s => s.SubjectName).FirstOrDefault();


                    if (rc.Batch_Subjects_Parts.Any(s => s.Batch.BatchName == batch &&
                                                    s.Batch.SectionID == section &&
                                                    s.Batch.DegreeProgram_ID == degree &&
                                                    s.Part == part &&
                                                    s.SubjectID == subjects))
                    {
                        return("Batch " + batch + " with DegreeProgram " + getDegreeName + " has already assigned Subject " + getSubjName + " in Part " + part);
                    }
                    if (rc.Batches.Any(s => s.BatchName == batch &&
                                       s.SectionID == section &&
                                       s.DegreeProgram_ID == degree))
                    {
                        //Add New Subject To Batch
                        //int getLastID = GetBatchSubjPart();
                        Batch_Subjects_Parts bps = new Batch_Subjects_Parts();
                        bps.ID        = Guid.NewGuid();
                        bps.Part      = part;
                        bps.BatchName = batch;
                        bps.SubjectID = subjects;
                        rc.Batch_Subjects_Parts.Add(bps);
                        rc.SaveChanges();

                        //Check to see if there is any batch student who is studing in that part
                        if (rc.Assign_Subject.Any(s => s.Batch_Subjects_Parts.BatchName == batch &&
                                                  s.Batch_Subjects_Parts.Batch.SectionID == section &&
                                                  s.Batch_Subjects_Parts.Batch.DegreeProgram_ID == degree &&
                                                  s.Batch_Subjects_Parts.Part == part))
                        {
                            ////Check To see on new Subject Assigned To Batch,
                            ////The Students that are not assigned that Subject,
                            ////should be assigned to that subject
                            bool checkerOnMatchedStudentThatisNotStudingThatParticularSubject = false;
                            //int AssignID = GetNewAssignID();

                            foreach (var item in studentsSpecificToABatch)
                            {
                                foreach (var item2 in item.Assign_Subject)
                                {
                                    if (item2.Batch_Subjects_Parts.BatchName == batch &&
                                        item2.Batch_Subjects_Parts.Batch.SectionID == section &&
                                        item2.Batch_Subjects_Parts.Batch.DegreeProgram_ID == degree &&
                                        item2.Batch_Subjects_Parts.Part == part &&
                                        item2.Batch_Subjects_Parts.SubjectID == subjects &&
                                        item.Status == 1)
                                    {
                                        checkerOnMatchedStudentThatisNotStudingThatParticularSubject = true;
                                    }
                                    if (checkerOnMatchedStudentThatisNotStudingThatParticularSubject == true)
                                    {
                                        break;
                                    }
                                }

                                if (checkerOnMatchedStudentThatisNotStudingThatParticularSubject == false)
                                {
                                    rc.Assign_Subject.Add(new Assign_Subject
                                    {
                                        Rollno           = item.Rollno,
                                        Batch_Subject_ID = bps.ID,
                                        Status           = "Active",
                                        Registeration    = item
                                    });
                                    rc.SaveChanges();
                                }
                                else
                                {
                                    checkerOnMatchedStudentThatisNotStudingThatParticularSubject = false;
                                }
                            }
                            rc.SaveChanges();
                            t.Complete();
                            return("OK");
                            //return "The Record with DegreeName: " + getDegreeName + ", Section: " + getSectionName + " Part: " + part + " ,Subject: " + getSubjName + " is Successfully added";
                        }
                        else
                        {
                            //No Worries Subjects are still added in batch only
                            //not To all the students
                            rc.SaveChanges();
                            t.Complete();
                            return("OK");
                        }
                    }
                    else
                    {
                        return("Plz Enter Correct Batch, Section, DegreeProgram Values");
                    }
                }
                catch
                {
                    return("Unable To Assign Subject To Batch " + batch);
                }
            }
        }