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); } }
public List <String> InsertTblEventAttendees(List <String> StudentList, int EventID) { List <String> EmailList = new List <string>(); try { foreach (var EmailID in StudentList) { if (CheckStudentExists.CheckAttendee(EmailID, EventID)) { EmailList.Add(EmailID); _eatDBContext.EventAttendees.Add( new EventAttendees { RegisteredStudents = _eatDBContext.RegisteredStudents.Where(m => m.EmailID == EmailID).FirstOrDefault(), EventDetails = _eatDBContext.EventDetails.Where(m => m.ID == EventID).FirstOrDefault(), QRString = "", isPresent = false, MailSent = false }); } } _eatDBContext.SaveChanges(); return(EmailList); } catch (Exception ex) { return(null); } }
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); }