Beispiel #1
0
        public List <String> InsertTblRegisteredStudents(DataTable StudentsData)
        {
            List <String> StudentList = new List <string>();

            try
            {
                foreach (DataRow student in StudentsData.Rows)
                {
                    String EmailID = student.ItemArray[3].ToString();
                    if (CheckStudentExists.CheckStudent(EmailID))
                    {
                        String CollegeName = student.ItemArray[5].ToString();
                        _eatDBContext.RegisteredStudents.Add(new RegisteredStudents
                        {
                            FirstName         = student.ItemArray[0].ToString(),
                            LastName          = student.ItemArray[1].ToString(),
                            ContactNumber     = student.ItemArray[2].ToString(),
                            EmailID           = student.ItemArray[3].ToString(),
                            StudentRollNumber = student.ItemArray[4].ToString(),
                            CollegeDetails    = _eatDBContext.Master_CollegeDetails.Where(m => m.CollegeName.Equals(CollegeName)).FirstOrDefault(),
                            CreatedBy         = 1,//Update with user sessionID
                            CreatedDate       = DateTime.Now
                        });
                    }
                    StudentList.Add(EmailID);
                }
                _eatDBContext.SaveChanges();
                return(StudentList);
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
                return(null);
            }
        }
Beispiel #2
0
        public Dictionary <string, string> InsertTblRegisteredStudents(DataTable studentsData)
        {
            var StudentList = new Dictionary <string, string>();

            foreach (DataRow student in studentsData.Rows)
            {
                string EmailID = student.Field <string>("EmailID");
                if (CheckStudentExists.CheckStudent(EmailID))
                {
                    RegisteredStudents registeredStudents = null;
                    try
                    {
                        string collegeName = student.Field <string>("CollegeName");
                        registeredStudents = new RegisteredStudents
                        {
                            FirstName         = student.Field <string>("FirstName"),
                            LastName          = student.Field <string>("LastName"),
                            ContactNumber     = student.Field <string>("ContactNumber"),
                            EmailID           = student.Field <string>("EmailID"),
                            StudentRollNumber = student.Field <string>("StudentRollNo"),
                            CollegeDetails    =
                                _eatDBContext.Master_CollegeDetails.Single(m => m.CollegeName.Equals(collegeName)),
                            CreatedBy   = 1, //Update with user sessionID
                            CreatedDate = DateTime.Now
                        };
                        _eatDBContext.RegisteredStudents.Add(registeredStudents);
                        int temp = _eatDBContext.SaveChanges();
                        if (!StudentList.ContainsKey(EmailID))
                        {
                            StudentList.Add(EmailID, "Successfully Inserted Data");
                        }
                    }
                    catch (Exception)
                    {
                        if (!StudentList.ContainsKey(EmailID))
                        {
                            StudentList.Add(EmailID, "Invalid Data");
                        }
                        _eatDBContext.RegisteredStudents.Remove(registeredStudents);
                    }
                }
                else
                {
                    if (!StudentList.ContainsKey(EmailID))
                    {
                        StudentList.Add(EmailID, "Duplicate Data");
                    }
                }
            }

            return(StudentList);
        }