示例#1
0
        public int AddOrUpdate(EducationalClassSyncModel educationalClass)
        {
            var groupRepo     = new EducationalGroupRepository(DatabaseFactory);
            var professorRepo = new ProfessorRepository(DatabaseFactory);
            var termRepo      = new TermRepository(DatabaseFactory);

            if (IsExist(x => x.CodeClass == educationalClass.CodeClass && x.Term.TermCode == educationalClass.Term))
            {
                //ToDO Update
                var r = Update(educationalClass, groupRepo, professorRepo, termRepo);
                if (r != 0)
                {
                    return(2);
                }
                return(3);
            }
            else
            {
                //ToDo Add
                var r = Add(educationalClass, groupRepo, professorRepo, termRepo);
                if (r != 0)
                {
                    return(1);
                }
                return(3);
            }
        }
        public int Update(GroupSyncModel ge)
        {
            var profRepo    = new ProfessorRepository(DatabaseFactory);
            var collegeRepo = new CollegeRepository(DatabaseFactory);
            var g           = DataContext.EducationalGroups
                              .FirstOrDefault(x => x.EducationalGroupCode == ge.EducationalGroupCode &&
                                              x.Term.TermCode == ge.Term);

            if (g != null)
            {
                g.Name               = ge.Name;
                g.IsActive           = ge.IsActive;
                g.GroupManger        = profRepo.GetMany(x => x.ProfessorCode == ge.GroupMangerId && x.Term.TermCode == ge.Term).FirstOrDefault();
                g.OnlinePresenceTime = ge.OnlinePresenceTime != 0 ? ge.OnlinePresenceTime : null;
                // g.PhysicalPresenceTime = ge.PhysicalPresenceTime != 0 ? ge.PhysicalPresenceTime : null;
                g.TotalStudentsCount        = ge.TotalStudentsCount != 0 ? ge.TotalStudentsCount : null;
                g.CancellationStudentsCount = ge.CancellationStudentsCount != 0 ? ge.CancellationStudentsCount : null;
                g.DismissedstudentsCount    = ge.DismissedstudentsCount != 0 ? ge.DismissedstudentsCount : null;
                g.TotalStudentScoresAverage = ge.TotlalStudentAverageScores != 0 ? ge.TotlalStudentAverageScores : null;
                g.TotalProfessorsCount      = ge.TotalProfessorsCount != 0 ? ge.TotalProfessorsCount : null;
                g.DoctoralProfessorsCount   = ge.DoctoralProfessorsCount != 0 ? ge.DoctoralProfessorsCount : null;
                g.MaProfessorsCount         = ge.MaProfessorsCount != 0 ? ge.MaProfessorsCount : null;
                g.BachelorProfessorsCount   = ge.BachelorProfessorsCount != 0 ? ge.BachelorProfessorsCount : null;
                g.TotalProposals            = ge.TotalProposals != 0 ? ge.TotalProposals : null;
                g.ApprovedProposals         = ge.ApprovedProposals != 0 ? ge.ApprovedProposals : null;
                g.College = collegeRepo.GetMany(x => x.CollegeCode == ge.CollegeId).FirstOrDefault();
                g.AverageBachelorStudentGrades = ge.BachelorStudentAverageScores != 0 ? ge.BachelorStudentAverageScores : null;
                g.AverageMaStudentGrades       = ge.MaStudentAverageScores != 0 ? ge.MaStudentAverageScores : null;
                g.AverageDoctoralStudentGrades = ge.DoctoralStudentAverageScores != 0 ? ge.DoctoralStudentAverageScores : null;
                g.LastModifiedDate             = DateTime.Now;
                //Calculatepr
                g.ExpelledStudentsPercentage = ge.TotalStudentsCount != 0
                    ? (ge.DismissedstudentsCount * 100) / ge.TotalStudentsCount
                    : null;
                g.StudentCancellationPercentage = ge.TotalStudentsCount != 0
                    ? (ge.CancellationStudentsCount * 100) / ge.TotalStudentsCount
                    : null;
                g.TeacherToBachelorStudentRatio = ge.BachelorProfessorsCount != 0
                    ? (ge.BachelorStudentCount / ge.BachelorProfessorsCount)
                    : null;
                g.TeacherToMaStudentRatio = ge.MaProfessorsCount != 0
                    ? (ge.MaStudentCount / ge.MaProfessorsCount)
                    : null;
                g.TeacherToDoctoralStudentRatio = ge.DoctoralProfessorsCount != 0
                    ? (ge.DoctoralStudentCount / ge.DoctoralProfessorsCount)
                    : null;
                g.ApproveProposalsPercentage = ge.TotalProposals != 0
                    ? (ge.ApprovedProposals * 100) / ge.TotalProposals
                    : null;
            }


            return(DataContext.SaveChanges());
        }
        public int Add(GroupSyncModel ge)
        {
            var profRepo    = new ProfessorRepository(DatabaseFactory);
            var termRepo    = new TermRepository(DatabaseFactory);
            var collegeRepo = new CollegeRepository(DatabaseFactory);

            var c = new EducationalGroup
            {
                Name        = ge.Name,
                IsActive    = ge.IsActive,
                GroupManger = profRepo
                              .GetMany(x => x.ProfessorCode == ge.GroupMangerId && x.Term.TermCode == ge.Term).FirstOrDefault(),
                OnlinePresenceTime        = ge.OnlinePresenceTime != 0 ? ge.OnlinePresenceTime : null,
                PhysicalPresenceTime      = ge.PhysicalPresenceTime != 0 ? ge.PhysicalPresenceTime : null,
                TotalStudentsCount        = ge.TotalStudentsCount != 0 ? ge.TotalStudentsCount : null,
                CancellationStudentsCount = ge.CancellationStudentsCount != 0 ? ge.CancellationStudentsCount : null,
                DismissedstudentsCount    = ge.DismissedstudentsCount != 0 ? ge.DismissedstudentsCount : null,
                TotalStudentScoresAverage = ge.TotlalStudentAverageScores != 0 ? ge.TotlalStudentAverageScores : null,
                TotalProfessorsCount      = ge.TotalProfessorsCount != 0 ? ge.TotalProfessorsCount : null,
                DoctoralProfessorsCount   = ge.DoctoralProfessorsCount != 0 ? ge.DoctoralProfessorsCount : null,
                MaProfessorsCount         = ge.MaProfessorsCount != 0 ? ge.MaProfessorsCount : null,
                BachelorProfessorsCount   = ge.BachelorProfessorsCount != 0 ? ge.BachelorProfessorsCount : null,
                TotalProposals            = ge.TotalProposals != 0 ? ge.TotalProposals : null,
                ApprovedProposals         = ge.ApprovedProposals != 0 ? ge.ApprovedProposals : null,
                College = collegeRepo.GetMany(x => x.CollegeCode == ge.CollegeId).FirstOrDefault(),
                AverageBachelorStudentGrades = ge.BachelorStudentAverageScores != 0 ? ge.BachelorStudentAverageScores : null,
                AverageMaStudentGrades       = ge.MaStudentAverageScores != 0 ? ge.MaStudentAverageScores : null,
                AverageDoctoralStudentGrades = ge.DoctoralStudentAverageScores != 0 ? ge.DoctoralStudentAverageScores : null,
                Term = termRepo.GetMany(x => x.TermCode == ge.Term).FirstOrDefault(),
                EducationalGroupCode = ge.EducationalGroupCode != 0 ? ge.EducationalGroupCode : null,
                CreationDate         = DateTime.Now,
                //Calculatepr
                ExpelledStudentsPercentage = ge.TotalStudentsCount != 0
                ? (ge.DismissedstudentsCount * 100) / ge.TotalStudentsCount : null,
                StudentCancellationPercentage = ge.TotalStudentsCount != 0
                ? (ge.CancellationStudentsCount * 100) / ge.TotalStudentsCount : null,
                TeacherToBachelorStudentRatio = ge.BachelorProfessorsCount != 0
                ? (ge.BachelorStudentCount / ge.BachelorProfessorsCount) : null,
                TeacherToMaStudentRatio = ge.MaProfessorsCount != 0
                ? (ge.MaStudentCount / ge.MaProfessorsCount) : null,
                TeacherToDoctoralStudentRatio = ge.DoctoralProfessorsCount != 0
                ? (ge.DoctoralStudentCount / ge.DoctoralProfessorsCount) : null,

                ApproveProposalsPercentage = ge.TotalProposals != 0
                ? (ge.ApprovedProposals * 100) / ge.TotalProposals : null,
            };

            DataContext.EducationalGroups.Add(c);
            return(DataContext.SaveChanges());
        }
        private int Update(ProfessorSyncModel model)
        {
            var pRepo     = new ProfessorRepository(DatabaseFactory);
            var professor = pRepo.GetMany(x => x.ProfessorCode == model.ProfessoreCode && x.Term.TermCode == model.Term)
                            .FirstOrDefault();

            professor.IsActive             = model.IsActive;
            professor.UniversityWorkPlace  = model.UniversityWorkPlace;
            professor.UniversityStudyPlace = model.UniversityStudyPlace;
            professor.AcademicDegree       = model.AcademicDegree;
            professor.TeachingExperience   = model.TeachingExperience;
            professor.ScientificRank       = model.ScientificRank;
            professor.Email            = model.Email;
            professor.Mobile           = model.Mobile;
            professor.NationalCode     = model.NationalCode;
            professor.Gender           = model.Gender;
            professor.Family           = model.Family;
            professor.Name             = model.Name;
            professor.Status           = model.Status;
            professor.LastModifiedDate = DateTime.Now;

            return(DataContext.SaveChanges());
        }
示例#5
0
        public int Update(EducationalClassSyncModel educationalClass, EducationalGroupRepository groupRepo, ProfessorRepository professorRepo, TermRepository termRepo)
        {
            if (!groupRepo.IsExist(y =>
                                   y.EducationalGroupCode == educationalClass.GroupId &&
                                   y.Term.TermCode == educationalClass.Term) ||
                !professorRepo.IsExist(y =>
                                       y.ProfessorCode == educationalClass.ProfessorId &&
                                       y.Term.TermCode == educationalClass.Term) ||
                !termRepo.IsExist(x => x.TermCode == educationalClass.Term))
            {
                return(0);
            }

            var item = DataContext.EducationalClasses
                       .FirstOrDefault(f => f.CodeClass == educationalClass.CodeClass && f.Term.TermCode == educationalClass.Term);


            if (item != null)
            {
                item.CodeClass = educationalClass.CodeClass;

                item.LastModifiedDate = DateTime.Now;

                item.EducationalGroup = groupRepo
                                        .GetMany(
                    g => g.EducationalGroupCode == educationalClass.GroupId &&
                    g.Term.TermCode == educationalClass.Term)
                                        .FirstOrDefault();

                item.IsActive = educationalClass.IsActive;

                item.Name = educationalClass.Name;

                item.OnlineHeldingCount = educationalClass.OnlineHeldingCount;

                item.LessonPlanSendDate       = educationalClass.LessonPlanSendDate;
                item.AggregationExamPaperDate = educationalClass.AggregationExamPaperDate;
                item.ReceiveExamPaperDate     = educationalClass.ReceiveExamPaperDate;


                //item.OthersHeldingCount = educationalClass.OthersHeldingCount;

                //item.PersentHeldingCount = educationalClass.PresentHeldingCount;

                item.Professor = professorRepo.GetMany(
                    g => g.ProfessorCode == educationalClass.ProfessorId &&
                    g.Term.TermCode == educationalClass.Term).FirstOrDefault();

                if (educationalClass.ProfessorDelayAndEarlier != null)
                {
                    item.ProfessorDelayAndEarlier = educationalClass.ProfessorDelayAndEarlier.Value;
                }

                item.Term = termRepo.GetMany(g => g.TermCode == educationalClass.Term).FirstOrDefault();

                int datePartYear  = 0;
                int datePartMonth = 0;
                int datePartDay   = 0;
                if (educationalClass.DeclaringScoreDate != null &&
                    int.TryParse(educationalClass.DeclaringScoreDate.Split('/')[0], out datePartYear) &&
                    int.TryParse(educationalClass.DeclaringScoreDate.Split('/')[1], out datePartMonth) &&
                    int.TryParse(educationalClass.DeclaringScoreDate.Split('/')[2], out datePartDay)
                    )
                {
                    item.DeclaringScoreDate = new DateTime(datePartYear, datePartMonth, datePartDay, new PersianCalendar());
                }
                else if (educationalClass.DeclaringScoreDate != null && educationalClass.DeclaringScoreDate.Split('/').Length > 1 && educationalClass.DeclaringScoreDate.Split('/')[2].Contains(' '))
                {
                    item.DeclaringScoreDate = DateTime.Parse(educationalClass.DeclaringScoreDate);
                }
                item.HoldingExamDate     = educationalClass.HoldingExamDate;
                item.LoadingQuestionDate = educationalClass.LoadingQuestionDate;
                //if (educationalClass.HoldingExamDate != null)
                //{
                //    var datePartYear = Convert.ToInt32(educationalClass.HoldingExamDate.Split('/')[0]);
                //    var datePartMonth = Convert.ToInt32(educationalClass.HoldingExamDate.Split('/')[1]);
                //    var datePartDay = Convert.ToInt32(educationalClass.HoldingExamDate.Split('/')[2]);
                //    item.HoldingExamDate = new DateTime(datePartYear, datePartMonth, datePartDay);
                //}
                //if (educationalClass.LoadingQuestionDate != null)
                //{
                //    var datePartYear = Convert.ToInt32(educationalClass.LoadingQuestionDate.Split('/')[0]);
                //    var datePartMonth = Convert.ToInt32(educationalClass.LoadingQuestionDate.Split('/')[1]);
                //    var datePartDay = Convert.ToInt32(educationalClass.LoadingQuestionDate.Split('/')[2]);
                //    item.LoadingQuestionDate = new DateTime(datePartYear, datePartMonth, datePartDay);
                //}
            }
            return(DataContext.SaveChanges());
        }
示例#6
0
        public int Add(EducationalClassSyncModel educationalClass, EducationalGroupRepository groupRepo, ProfessorRepository professorRepo, TermRepository termRepo)
        {
            if (!groupRepo.IsExist(y =>
                                   y.EducationalGroupCode == educationalClass.GroupId && y.Term.TermCode == educationalClass.Term) ||
                !professorRepo.IsExist(y =>
                                       y.ProfessorCode == educationalClass.ProfessorId && y.Term.TermCode == educationalClass.Term) ||
                !termRepo.IsExist(x => x.TermCode == educationalClass.Term))
            {
                return(0);
            }

            var item = new EducationalClass
            {
                CodeClass        = educationalClass.CodeClass,
                CreationDate     = DateTime.Now,
                LastModifiedDate = DateTime.Now,

                EducationalGroup = groupRepo
                                   .GetMany(
                    g => g.EducationalGroupCode == educationalClass.GroupId &&
                    g.Term.TermCode == educationalClass.Term)
                                   .FirstOrDefault(),

                IsActive = educationalClass.IsActive,

                Name = educationalClass.Name,

                OnlineHeldingCount = educationalClass.OnlineHeldingCount,

                OthersHeldingCount = educationalClass.OthersHeldingCount,

                PersentHeldingCount = educationalClass.PresentHeldingCount,

                Professor = professorRepo.GetMany(
                    g => g.ProfessorCode == educationalClass.ProfessorId &&
                    g.Term.TermCode == educationalClass.Term).FirstOrDefault(),

                ReceiveExamPaperDate     = educationalClass.ReceiveExamPaperDate,
                AggregationExamPaperDate = educationalClass.AggregationExamPaperDate,
                LessonPlanSendDate       = educationalClass.LessonPlanSendDate,

                Term = termRepo.GetMany(g => g.TermCode == educationalClass.Term).FirstOrDefault()
            };

            if (educationalClass.ProfessorDelayAndEarlier != null)
            {
                item.ProfessorDelayAndEarlier = educationalClass.ProfessorDelayAndEarlier.Value;
            }

            if (educationalClass.DeclaringScoreDate != null)
            {
                var datePartYear  = Convert.ToInt32(educationalClass.DeclaringScoreDate.Split('/')[0]);
                var datePartMonth = Convert.ToInt32(educationalClass.DeclaringScoreDate.Split('/')[1]);
                var datePartDay   = Convert.ToInt32(educationalClass.DeclaringScoreDate.Split('/')[2]);
                item.DeclaringScoreDate = new DateTime(datePartYear, datePartMonth, datePartDay, new PersianCalendar());
            }
            item.HoldingExamDate     = educationalClass.HoldingExamDate;
            item.LoadingQuestionDate = educationalClass.LoadingQuestionDate;
            //if (educationalClass.HoldingExamDate != null)
            //{
            //    var datePartYear = Convert.ToInt32(educationalClass.HoldingExamDate.Split('/')[0]);
            //    var datePartMonth = Convert.ToInt32(educationalClass.HoldingExamDate.Split('/')[1]);
            //    var datePartDay = Convert.ToInt32(educationalClass.HoldingExamDate.Split('/')[2]);
            //    item.HoldingExamDate = new DateTime(datePartYear, datePartMonth, datePartDay, new PersianCalendar());
            //}
            //if (educationalClass.LoadingQuestionDate != null)
            //{
            //    var datePartYear = Convert.ToInt32(educationalClass.LoadingQuestionDate.Split('/')[0]);
            //    var datePartMonth = Convert.ToInt32(educationalClass.LoadingQuestionDate.Split('/')[1]);
            //    var datePartDay = Convert.ToInt32(educationalClass.LoadingQuestionDate.Split('/')[2]);
            //    item.LoadingQuestionDate = new DateTime(datePartYear, datePartMonth, datePartDay, new PersianCalendar());
            //}

            DataContext.EducationalClasses.Add(item);
            try
            {
                return(DataContext.SaveChanges());
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }