Пример #1
0
        private static void uploadStudentsToDb(List<StudentModel> studentsFullList, int branchId)
        {
            pickmepleasedbEntities1 p = new pickmepleasedbEntities1();
            List<StudentModel> errorList = new List<StudentModel>();
            foreach (var s in studentsFullList)
            //studentsFullList.ForEach(s =>
            {
                //remove permissions in the pickup
                //Yes, we give permission for Englilush Ltd. to publish photos including our child/children on website and marketing materials.
                //No, we do not give permission for Englilush Ltd. to publish photos including our child/children on website and marketing materials.
                bool resetPicker = false;
                foreach (var picker in s.PickUpOptions)
                {
                    if (picker.Contains("for Englilush Ltd"))
                        resetPicker = true;
                }

                if (resetPicker)
                    s.PickUpOptions = new List<string>();

                students newStudent = new students()
                {

                    user_id = s.StudentID,
                    address = s.Address,
                    //email_1 = s.Parent2Email,
                    first_name = s.FirstName,
                    image = "",
                    last_name = s.LastName,
                    phone_home = s.HomeNum,

                    parent_a_email = s.Parent1Email,
                    parent_a_first_name = s.Parent1Name,
                    parent_a_last_name = s.LastName,
                    parent_a_phone_mobile = s.Parent1Num,

                    parent_b_email = s.Parent2Email,
                    parent_b_first_name = s.Parent2Name,
                    parent_b_last_name = s.LastName,
                    parent_b_phone_mobile = s.Parent2Num,

                    birthday = s.BirthDay,
                    branch_id = branchId,
                    @class = s.SClass ?? "0",
                    gender = s.Gender == "Male",
                    grade = s.Grade ?? "0",
                    health_issues = (s.HealthIssues != null) ? string.Join("*", s.HealthIssues) : null,
                    is_active = true,
                    pick_up_options = (s.PickUpOptions != null) ? string.Join("*", s.PickUpOptions) : null,

                };
                try
                {
                    if (s.Grade.Length > 19 || s.SClass.Length > 19)
                    {
                        errorList.Add(s);
                    }
                    else
                    {
                        p.students.Add(newStudent);
                        //p.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(newStudent.first_name + ", " + newStudent.last_name);
                    errorList.Add(s);
                    p.students.Remove(newStudent);
                    //throw;
                }
            }
            try
            {
                p.SaveChanges();
            }
            catch (Exception ex)
            {

                //throw;
            }
            //});
            p.SaveChanges();
        }
Пример #2
0
        internal static void LoadCsv(List<string[]> data, int branchId)
        {
            pickmepleasedbEntities1 p = new pickmepleasedbEntities1();
            if (data == null)
                return;
            foreach (string[] row in data)
            {
                //student
                DateTime bDay = DateTime.MinValue;
                try
                {
                    bDay = DateTime.ParseExact(row[10], "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                }
                catch (Exception ex)
                {
                    //linesError.AppendLine("Bad BirthDay format");
                    //throw;
                }
                string gradeAndClass = row[9];
                string Grade, sClass;
                GetFormattedGrageAndClass(gradeAndClass, out  Grade, out  sClass);

                students s = new students()
                {
                    first_name = row[3],
                    last_name = row[4],
                    user_id = row[5],
                    address = row[13],
                    phone_home = row[14],
                    parent_a_first_name = row[15],
                    parent_a_last_name = row[4],
                    parent_a_phone_mobile = row[16],
                    parent_a_email = row[17],
                    parent_b_first_name = row[18],
                    parent_b_last_name = row[4],
                    parent_b_phone_mobile = row[19],
                    parent_b_email = row[20],

                    birthday = bDay,
                    branch_id = branchId,
                    @class = sClass,
                    grade = Grade,
                    gender = (row[11] == "Male") ? true : false,
                    health_issues = row[21],
                    pick_up_options = row[22]
                };
                p.students.Add(s);
                p.SaveChanges();

            }
        }