Exemplo n.º 1
0
        private StudentCompleteData GetStudent(Student_ProfileData studentProfileData)
        {
            try
            {
                var location        = System.Web.Hosting.HostingEnvironment.MapPath("~/PassportPictureFiles/Students") ?? "";
                var pictureFileInfo = new FileInfo(Path.Combine(location, $"{CleanDataForFileName(studentProfileData.MatricNumber)}.jpg"));

                if (!pictureFileInfo.Exists)
                {
                    pictureFileInfo = new FileInfo(Path.Combine(location, studentProfileData.MatricNumber
                                                                .Replace("-", "0")
                                                                .Replace("_", "0")
                                                                .Replace("/", "0")
                                                                .Replace("\\", "0") + ".png"));
                }

                if (pictureFileInfo.Exists)
                {
                    studentProfileData.Picture =
                        Convert.ToBase64String(System.IO.File.ReadAllBytes(pictureFileInfo.FullName));
                }

                return(new StudentCompleteData()
                {
                    StudentProfileData = studentProfileData,
                    StudentData = _entities.Student_RegistrationData
                                  .Where(x => !x.IsDeleted && x.StudentId == studentProfileData.Id)
                                  .Select(studentRegData => new StudentData()
                    {
                        StudentRegistrationData = studentRegData,
                        StudentCourseRegistration = _entities.Student_CourseRegistration
                                                    .Where(course =>
                                                           !course.IsDeleted &&
                                                           course.AcademicPeriodId == studentRegData.AcademicPeriodId &&
                                                           course.SchoolIdId == studentRegData.SchoolId &&
                                                           course.SubSchoolId == studentRegData.SubSchoolId &&
                                                           course.SubSchoolDepartmentId == studentRegData.SubSchoolDepartmentId)
                                                    .ToList()
                    }).ToList()
                });
            }
            catch (Exception e)
            {
                ActivityLogger.Log(e);
                return(null);
            }
        }
        private void ProcessStudentSchoolCustom(DataSet dataSet, bool forceReplace, string notifyDestination)
        {
            try
            {
                var innerentities = new Entities();
                var returnData    = new List <List <string> >();

                foreach (DataTable table in dataSet.Tables)
                {
                    _returnDataPerTable = new List <string>();

                    foreach (DataRow dataRow in table.Rows)
                    {
                        var matricNumber = dataRow[1].ToString().Trim();

                        if (string.IsNullOrEmpty(matricNumber))
                        {
                            continue;
                        }

                        var studentData =
                            innerentities.Student_ProfileData.FirstOrDefault(
                                x => !x.IsDeleted && x.MatricNumber == matricNumber);

                        var names = ProcessStudentSchoolCustomNameSplit(dataRow[2].ToString());

                        try
                        {
                            if (studentData == null)
                            {
                                var newStudentInfo = new Student_ProfileData()
                                {
                                    MatricNumber = matricNumber,
                                    FirstName    = names[0],
                                    LastName     = names[1],
                                    Sex          = dataRow[3].ToString().Trim(),
                                    BloodGroup   = dataRow[5].ToString().Trim(),
                                    Phone        = dataRow[6].ToString().Trim(),
                                    Email        = dataRow[7].ToString().Trim(),
                                    IsDeleted    = false,
                                };

                                innerentities.Student_ProfileData.Add(newStudentInfo);
                                innerentities.SaveChanges();

                                studentData = newStudentInfo;
                            }
                            else
                            {
                                if (forceReplace)
                                {
                                    studentData.FirstName  = names[0];
                                    studentData.LastName   = names[1];
                                    studentData.Sex        = dataRow[3].ToString().Trim();
                                    studentData.Phone      = dataRow[6].ToString().Trim();
                                    studentData.Email      = dataRow[7].ToString().Trim();
                                    studentData.BloodGroup = dataRow[5].ToString().Trim();

                                    innerentities.Entry(studentData).State = EntityState.Modified;
                                    innerentities.SaveChanges();
                                }
                            }

                            var subSchoolId           = ProcessSubSchoolEntry(dataRow[4].ToString().Trim());
                            var subSchooDepartmentlId = ProcessSubSchoolDepartmentEntry(subSchoolId, dataRow[0].ToString().Trim());

                            if (innerentities.Student_RegistrationData.Any(x =>
                                                                           !x.IsDeleted && x.SubSchoolId == subSchoolId && x.AcademicPeriodId == 1 &&
                                                                           x.SchoolId == 1 && x.SubSchoolDepartmentId == subSchooDepartmentlId &&
                                                                           x.StudentId == studentData.Id))
                            {
                                continue;
                            }

                            innerentities.Student_RegistrationData.Add(new Student_RegistrationData()
                            {
                                AcademicPeriodId      = 1,
                                DateRegistered        = DateTime.Now,
                                IsDeleted             = false,
                                SchoolId              = 1,
                                StudentId             = studentData.Id,
                                SubSchoolDepartmentId = subSchooDepartmentlId,
                                SubSchoolId           = subSchoolId
                            });
                            innerentities.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            ActivityLogger.Log(ex);
                            innerentities = new Entities();
                            TreatProcessingError(ex, dataRow.ItemArray);
                        }
                    }

                    returnData.Add(_returnDataPerTable);
                }

                FinalizeFileUpload(returnData, dataSet, notifyDestination);
            }
            catch (Exception e)
            {
                ActivityLogger.Log(e);
            }
        }
        private void ProcessStudentEdBoxPre(DataSet dataSet, bool forceReplace, string notifyDestination)
        {
            try
            {
                var innerentities = new Entities();
                var returnData    = new List <List <string> >();

                foreach (DataTable table in dataSet.Tables)
                {
                    _returnDataPerTable = new List <string>();

                    foreach (DataRow dataRow in table.Rows)
                    {
                        var matricNumber = dataRow[0].ToString().Trim();

                        if (string.IsNullOrEmpty(matricNumber))
                        {
                            continue;
                        }

                        var studentData =
                            innerentities.Student_ProfileData.FirstOrDefault(
                                x => !x.IsDeleted && x.MatricNumber == matricNumber);

                        dataRow[4] = dataRow[4].ToString().Split('/')[0].Trim();

                        try
                        {
                            if (forceReplace)
                            {
                                if (studentData == null)
                                {
                                    var newStudentInfo = new Student_ProfileData()
                                    {
                                        MatricNumber = dataRow[0].ToString().Trim(),
                                        FirstName    = dataRow[1].ToString().Trim(),
                                        LastName     = dataRow[2].ToString().Trim(),
                                        Sex          = dataRow[3].ToString().Trim(),
                                        Phone        = dataRow[4].ToString().Trim(),
                                        Email        = dataRow[5].ToString().Trim(),
                                        IsDeleted    = false,
                                    };

                                    innerentities.Student_ProfileData.Add(newStudentInfo);
                                    innerentities.SaveChanges();
                                }
                                else
                                {
                                    try
                                    {
                                        studentData.FirstName = dataRow[1].ToString().Trim();
                                        studentData.LastName  = dataRow[2].ToString().Trim();
                                        studentData.Sex       = dataRow[3].ToString().Trim();
                                        studentData.Phone     = dataRow[4].ToString().Trim();
                                        studentData.Email     = dataRow[5].ToString().Trim();

                                        innerentities.Entry(studentData).State = EntityState.Modified;
                                        innerentities.SaveChanges();
                                    }
                                    catch (Exception ex)
                                    {
                                        innerentities = new Entities();
                                        ActivityLogger.Log(ex);
                                        TreatProcessingError(ex, dataRow.ItemArray);
                                    }
                                }
                            }
                            else
                            {
                                var newStudentInfo = new Student_ProfileData()
                                {
                                    MatricNumber = dataRow[0].ToString().Trim(),
                                    FirstName    = dataRow[1].ToString().Trim(),
                                    LastName     = dataRow[2].ToString().Trim(),
                                    Sex          = dataRow[3].ToString().Trim(),
                                    Phone        = dataRow[4].ToString().Trim(),
                                    Email        = dataRow[5].ToString().Trim(),
                                    IsDeleted    = false,
                                };

                                innerentities.Student_ProfileData.Add(newStudentInfo);
                                innerentities.SaveChanges();
                            }
                        }
                        catch (Exception ex)
                        {
                            ActivityLogger.Log(ex);
                            innerentities = new Entities();
                            TreatProcessingError(ex, dataRow.ItemArray);
                        }
                    }

                    returnData.Add(_returnDataPerTable);
                }

                FinalizeFileUpload(returnData, dataSet, notifyDestination);
            }
            catch (Exception e)
            {
                ActivityLogger.Log(e);
            }
        }