Esempio n. 1
0
        public static int ProocessNewStudentAddmission(Students newStudent, Admissions newAdmission, FeeCollections newFeeCollection)
        {
            using (VedantaEntities ve = new VedantaEntities())
            {
                Students oldStudent = ve.Students.FirstOrDefault(st => st.ID == newStudent.ID);

                int newStudentId = 0; int oldStudentId = 0;
                //Add A New Student Record in DataBase if that student does not exists
                if (oldStudent == null)
                {
                    newStudent.CreatedDate = DateTime.Now.Date;
                    ve.AddToStudents(newStudent);
                    ve.SaveChanges();
                    newStudentId = newStudent.ID;
                }
                else
                {
                    oldStudentId = oldStudent.ID;
                }

                //If Student is already enrolled with us then no need to add new record for same student
                if (newStudentId == 0 && oldStudentId > 0)
                {
                    newStudentId = oldStudentId;
                }

                if (newStudentId > 0)
                {
                    newAdmission.StudentId = newStudentId;

                    Admissions oldAdmission = ve.Admissions.FirstOrDefault(ad => ad.StudentId == newStudentId && ad.CourseId == newAdmission.CourseId);
                    if (oldAdmission == null)
                    {
                        ve.AddToAdmissions(newAdmission);
                        int admResult = ve.SaveChanges();
                        return(admResult);
                        //if (admResult > 0)   //Admission of Student done successfully.
                        //{
                        //    newFeeCollection.AdmissionId = newAdmission.Id;
                        //    ve.AddToFeeCollections(newFeeCollection);
                        //    return ve.SaveChanges(); //Admission Fee Paid successfully.
                        //}
                        //else
                        //    return -2;
                    }
                    else
                    {
                        return(-2); //Student Record Entered but failed to take Admission of student.
                    }
                }
                else
                {
                    return(-1); //Student Record not entered;
                }
            }
        }