Exemple #1
0
 public int Insert(Countries Country)
 {
     try
     {
         using (var db = new HCMEntities())
         {
             db.Countries.Add(Country);
             db.SaveChanges();
             return(Country.CountryID);
         }
     }
     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;
     }
 }
Exemple #2
0
 public int EndLender(Lenders Lender)
 {
     try
     {
         using (var db = new HCMEntities())
         {
             Lenders LenderObj = db.Lenders.SingleOrDefault(x => x.LenderID.Equals(Lender.LenderID));
             LenderObj.LenderStartDate         = Lender.LenderStartDate;
             LenderObj.LenderEndDate           = Lender.LenderEndDate;
             LenderObj.EmployeeCareerHistoryID = Lender.EmployeeCareerHistoryID;
             LenderObj.IsFinished         = Lender.IsFinished;
             LenderObj.LenderOrganization = Lender.LenderOrganization;
             LenderObj.KSACityID          = Lender.KSACityID;
             LenderObj.LenderEndReason    = "" + Lender.LenderEndReason;
             LenderObj.LastUpdatedDate    = Lender.LastUpdatedDate;
             LenderObj.LastUpdatedBy      = Lender.LastUpdatedBy;
             return(db.SaveChanges());
         }
     }
     catch
     {
         throw;
     }
 }
Exemple #3
0
 public int Update(JobsCategories JobCategory)
 {
     try
     {
         using (var db = new HCMEntities())
         {
             JobsCategories JobCategoryObj = db.JobsCategories.SingleOrDefault(x => x.JobCategoryID.Equals(JobCategory.JobCategoryID));
             JobCategoryObj.JobCategoryID              = JobCategory.JobCategoryID;
             JobCategoryObj.JobCategoryName            = JobCategory.JobCategoryName;
             JobCategoryObj.JobGroupID                 = JobCategory.JobGroupID;
             JobCategoryObj.LastUpdatedDate            = DateTime.Now;
             JobCategoryObj.LastUpdatedBy              = JobCategory.LastUpdatedBy;
             JobCategoryObj.MinGeneralSpecializationID = JobCategory.MinGeneralSpecializationID;
             JobCategoryObj.MinQualificationDegreeID   = JobCategory.MinQualificationDegreeID;
             JobCategoryObj.MinQualificationID         = JobCategory.MinQualificationID;
             JobCategoryObj.JobCategoryNo              = JobCategory.JobCategoryNo;
             return(db.SaveChanges());
         }
     }
     catch
     {
         throw;
     }
 }
        public List <InsteadDeportations> GetInsteadDeportations(out int totalRecordsOut, out int recFilterOut)
        {
            try
            {
                var db = new HCMEntities();
                //return db.Delegations.Include("DelegationsKinds")
                //                     .Include("DelegationsTypes")
                //                     .Include("KSACities")
                //                     .Include("KSACities.KSARegions")
                //                     .Include("Countries")
                //                     .Include("CreatedByNav.Employees")
                //                     .Include("LastUpdatedByNav.Employees")
                //                     .ToList();


                //var odData = db.InsteadDeportations
                //                        .Include("Deportations")
                //                        .Include("EmployeesCareersHistory");

                var odData = db.InsteadDeportations
                             .Include("EmployeesCareersHistory");

                odData = odData.Include("EmployeesCareersHistory.EmployeesCodes.Employees");


                odData = odData.Include("CreatedByNav.Employees")
                         .Include("LastUpdatedByNav.Employees");

                // Total record count.
                totalRecordsOut = odData.Count();

                IQueryable <InsteadDeportations> iq = odData.Where(p => p.InsteadDeportationID != null);
                // Verification.
                if (!string.IsNullOrEmpty(search) &&
                    !string.IsNullOrWhiteSpace(search))
                {
                    // Apply search
                    iq = iq.Where(p =>
                                  p.InsteadDeportationID.ToString().ToLower().Contains(search.ToLower()) ||
                                  p.EmployeesCareersHistory.EmployeesCodes.EmployeeCodeNo.ToLower().Contains(search.ToLower()) ||
                                  (p.EmployeesCareersHistory.EmployeesCodes.Employees.FirstNameAr + " " + p.EmployeesCareersHistory.EmployeesCodes.Employees.MiddleNameAr + " " + p.EmployeesCareersHistory.EmployeesCodes.Employees.GrandFatherNameAr + " " + p.EmployeesCareersHistory.EmployeesCodes.Employees.LastNameAr).ToLower().Contains(search.ToLower()) ||
                                  p.EmployeesCareersHistory.OrganizationsJobs.Jobs.JobName.ToLower().Contains(search.ToLower()) ||
                                  p.DeportationDate.ToString().ToLower().Contains(search.ToLower())
                                  );
                }
                // Sorting.
                //iqOD = this.SortByColumnWithOrder2(order, orderDir, iqOD);
                iq = iq.OrderBy(p => p.InsteadDeportationID);
                // Filter record count.
                recFilterOut = iq.Count();

                // Apply pagination.
                iq = iq.Skip(startRec).Take(pageSize);
                //Get list of data
                var data = iq.ToList();

                return(data);
            }
            catch
            {
                throw;
            }
        }
Exemple #5
0
        public int ShuffleJob(PromotionsRecordsEmployees CurrentEmployee, PromotionsRecordsEmployees NewEmployee)
        {
            try
            {
                int result = 0;
                using (var db = new HCMEntities())
                {
                    using (var dbContextTransaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            int?CurrentPromotionRecordJobVacancyID = CurrentEmployee.PromotionRecordJobVacancyID;
                            int?NewPromotionRecordJobVacancyID     = NewEmployee.PromotionRecordJobVacancyID;

                            // first make both objects vacancyID = null
                            PromotionsRecordsEmployees CurrentEmployeeObj = db.PromotionsRecordsEmployees.SingleOrDefault(x => x.PromotionRecordEmployeeID.Equals(CurrentEmployee.PromotionRecordEmployeeID));
                            CurrentEmployeeObj.PromotionRecordJobVacancyID = null;
                            CurrentEmployeeObj.LastUpdatedBy   = CurrentEmployee.LastUpdatedBy;
                            CurrentEmployeeObj.LastUpdatedDate = DateTime.Now;

                            PromotionsRecordsEmployees NewEmployeeObj = db.PromotionsRecordsEmployees.SingleOrDefault(x => x.PromotionRecordEmployeeID.Equals(NewEmployee.PromotionRecordEmployeeID));
                            NewEmployeeObj.PromotionRecordJobVacancyID = null;
                            NewEmployeeObj.LastUpdatedBy   = NewEmployeeObj.LastUpdatedBy;
                            NewEmployeeObj.LastUpdatedDate = DateTime.Now;

                            db.PromotionsRecordsEmployees.AddOrUpdate(CurrentEmployeeObj);
                            db.PromotionsRecordsEmployees.AddOrUpdate(NewEmployeeObj);

                            result = db.SaveChanges();

                            // now shuffle the vacancy ID

                            CurrentEmployeeObj = db.PromotionsRecordsEmployees.SingleOrDefault(x => x.PromotionRecordEmployeeID.Equals(CurrentEmployee.PromotionRecordEmployeeID));
                            CurrentEmployeeObj.PromotionRecordJobVacancyID = NewPromotionRecordJobVacancyID;
                            CurrentEmployeeObj.LastUpdatedBy   = CurrentEmployee.LastUpdatedBy;
                            CurrentEmployeeObj.LastUpdatedDate = DateTime.Now;

                            NewEmployeeObj = db.PromotionsRecordsEmployees.SingleOrDefault(x => x.PromotionRecordEmployeeID.Equals(NewEmployee.PromotionRecordEmployeeID));
                            NewEmployeeObj.PromotionRecordJobVacancyID = CurrentPromotionRecordJobVacancyID;
                            NewEmployeeObj.LastUpdatedBy   = NewEmployeeObj.LastUpdatedBy;
                            NewEmployeeObj.LastUpdatedDate = DateTime.Now;

                            db.PromotionsRecordsEmployees.AddOrUpdate(CurrentEmployeeObj);
                            db.PromotionsRecordsEmployees.AddOrUpdate(NewEmployeeObj);

                            result = db.SaveChanges();

                            dbContextTransaction.Commit();
                        }
                        catch (Exception)
                        {
                            dbContextTransaction.Rollback();
                            throw;
                        }
                    }
                    return(result);
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #6
0
        public List <PromotionsRecordsEmployees> GetByPromotionRecordID(int PromotionRecordID, bool?IsIncluded, out int totalRecordsOut, out int recFilterOut)
        {
            try
            {
                var db = new HCMEntities();
                PromotionsRecords PromotionRecord = new PromotionsRecordsDAL().GetByPromotionRecordID(PromotionRecordID);

                var odData = db.PromotionsRecordsEmployees
                             .Include("PromotionsRecords")
                             .Include("CurrentEmployeesCareersHistory")
                             .Include("CurrentEmployeesCareersHistory.EmployeesCodes.Employees")
                             .Include("CurrentEmployeesCareersHistory.OrganizationsJobs.OrganizationsStructures")
                             .Include("CurrentEmployeesCareersHistory.OrganizationsJobs.Jobs")
                             .Include("CurrentEmployeesCareersHistory.OrganizationsJobs.Ranks")
                             .Include("NewEmployeesCareersHistory")
                             .Include("NewEmployeesCareersHistory.EmployeesCodes.Employees")
                             .Include("NewEmployeesCareersHistory.OrganizationsJobs.OrganizationsStructures")
                             .Include("NewEmployeesCareersHistory.OrganizationsJobs.Jobs")
                             .Include("NewEmployeesCareersHistory.OrganizationsJobs.Ranks")
                             .Include("PreviousEmployeesCareersHistory")
                             .Include("PreviousEmployeesCareersHistory.EmployeesCodes.Employees")
                             .Include("PreviousEmployeesCareersHistory.OrganizationsJobs.OrganizationsStructures")
                             .Include("PreviousEmployeesCareersHistory.OrganizationsJobs.Jobs")
                             .Include("PreviousEmployeesCareersHistory.OrganizationsJobs.Ranks")
                             .Include("PromotionsCandidatesAddedWays")
                             .Include("ApprovedByNav")
                             .Include("ApprovedByNav.Employees")
                             .Include("RemovingByNav")
                             .Include("RemovingByNav.Employees")
                             .Include("LastQualificationsDegrees")
                             .Include("LastQualifications")
                             .Include("LastGeneralSpecializations")
                             .Include("PromotionsDecisions")
                             .Include("PromotionsRecordsJobsVacancies")
                             .Include("PromotionsRecordsJobsVacancies.OrganizationsJobs")
                             .Where(x => x.PromotionRecordID == PromotionRecordID &&
                                    (IsIncluded.HasValue ? x.IsIncluded == IsIncluded.Value : 1 == 1));

                // Total record count.
                totalRecordsOut = odData.Count();

                IQueryable <PromotionsRecordsEmployees> iq = odData.Where(p => p.PromotionRecordEmployeeID != null);

                // Verification.
                if (!string.IsNullOrEmpty(search) &&
                    !string.IsNullOrWhiteSpace(search))
                {
                    // Apply search
                    iq = iq.Where(p =>
                                  (p.CurrentEmployeesCareersHistory.EmployeesCodes.Employees.FirstNameAr + " " + p.CurrentEmployeesCareersHistory.EmployeesCodes.Employees.MiddleNameAr + " " + p.CurrentEmployeesCareersHistory.EmployeesCodes.Employees.GrandFatherNameAr + " " + p.CurrentEmployeesCareersHistory.EmployeesCodes.Employees.LastNameAr).ToLower().Contains(search.ToLower()) ||
                                  p.CurrentEmployeesCareersHistory.EmployeesCodes.EmployeeCodeNo.ToLower().Contains(search.ToLower()) ||
                                  p.CurrentEmployeesCareersHistory.EmployeesCodes.Employees.EmployeeIDNo.ToLower().Contains(search.ToLower()) ||

                                  p.CurrentEmployeesCareersHistory.OrganizationsJobs.JobNo.ToLower().Contains(search.ToLower()) ||
                                  p.CurrentEmployeesCareersHistory.OrganizationsJobs.Jobs.JobCode.ToLower().Contains(search.ToLower()) ||
                                  p.CurrentEmployeesCareersHistory.OrganizationsJobs.Jobs.JobName.ToLower().Contains(search.ToLower()) ||
                                  p.CurrentEmployeesCareersHistory.OrganizationsJobs.OrganizationsStructures.OrganizationName.ToLower().Contains(search.ToLower()) ||
                                  p.CurrentEmployeesCareersHistory.OrganizationsJobs.Jobs.JobsCategories.JobCategoryName.ToLower().Contains(search.ToLower()) ||
                                  p.CurrentEmployeesCareersHistory.OrganizationsJobs.Ranks.RankName.ToLower().Contains(search.ToLower()) ||

                                  (p.NewEmployeesCareersHistory != null && (p.NewEmployeesCareersHistory.EmployeesCodes.Employees.FirstNameAr + " " + p.NewEmployeesCareersHistory.EmployeesCodes.Employees.MiddleNameAr + " " + p.NewEmployeesCareersHistory.EmployeesCodes.Employees.GrandFatherNameAr + " " + p.NewEmployeesCareersHistory.EmployeesCodes.Employees.LastNameAr).ToLower().Contains(search.ToLower())) ||
                                  (p.NewEmployeesCareersHistory != null && p.NewEmployeesCareersHistory.EmployeesCodes.EmployeeCodeNo.ToLower().Contains(search.ToLower())) ||
                                  (p.NewEmployeesCareersHistory != null && p.NewEmployeesCareersHistory.EmployeesCodes.Employees.EmployeeIDNo.ToLower().Contains(search.ToLower())) ||
                                  (p.NewEmployeesCareersHistory != null && p.CurrentEmployeesCareersHistory.OrganizationsJobs.JobNo.ToLower().Contains(search.ToLower())) ||
                                  (p.NewEmployeesCareersHistory != null && p.CurrentEmployeesCareersHistory.OrganizationsJobs.Jobs.JobCode.ToLower().Contains(search.ToLower())) ||
                                  (p.NewEmployeesCareersHistory != null && p.CurrentEmployeesCareersHistory.OrganizationsJobs.Jobs.JobName.ToLower().Contains(search.ToLower())) ||
                                  (p.NewEmployeesCareersHistory != null && p.CurrentEmployeesCareersHistory.OrganizationsJobs.OrganizationsStructures.OrganizationName.ToLower().Contains(search.ToLower())) ||
                                  (p.NewEmployeesCareersHistory != null && p.CurrentEmployeesCareersHistory.OrganizationsJobs.Jobs.JobsCategories.JobCategoryName.ToLower().Contains(search.ToLower())) ||
                                  (p.NewEmployeesCareersHistory != null && p.CurrentEmployeesCareersHistory.OrganizationsJobs.Ranks.RankName.ToLower().Contains(search.ToLower()))

                                  );
                }

                // Sorting.
                if (PromotionRecord.PromotionRecordStatusID == 1)        // Open
                {
                    iq = iq.OrderBy(p => (p.CurrentEmployeesCareersHistory.EmployeesCodes.Employees.FirstNameAr + " " + p.CurrentEmployeesCareersHistory.EmployeesCodes.Employees.MiddleNameAr + " " + p.CurrentEmployeesCareersHistory.EmployeesCodes.Employees.GrandFatherNameAr + " " + p.CurrentEmployeesCareersHistory.EmployeesCodes.Employees.LastNameAr));
                }
                else
                {
                    iq = iq.OrderBy(p => p.PromotionDecisionID.HasValue ? p.PromotionDecisionID.Value : 9999)
                         .OrderByDescending(p => new
                    {
                        //Included = (p.IsIncluded ? 1 : 0) + (p.IsRemovedAfterIncluding.HasValue ? (p.IsRemovedAfterIncluding.Value ? 0 : 1) : 1),
                        //PromotionDecisionID = p.PromotionDecisionID.HasValue ? p.PromotionDecisionID.Value : 999,
                        TotalPoints = (p.EducationPoints.HasValue ? p.EducationPoints.Value : 0) +
                                      (p.SeniorityPoints.HasValue ? p.SeniorityPoints.Value : 0) +
                                      (p.EvaluationPoints.HasValue ? p.EvaluationPoints.Value : 0) +
                                      (p.ActualTaskPerformancePoints),
                        LastQualification    = p.LastQualificationsDegrees != null ? (p.LastQualificationsDegrees.Weight.HasValue ? p.LastQualificationsDegrees.Weight.Value : 0) : 0,
                        CurrentJobDaysCount  = p.CurrentJobDaysCount.HasValue ? p.CurrentJobDaysCount.Value : 0,
                        PreviousJobDaysCount = p.PreviousJobDaysCount,
                        TotalExperience      = (p.OnGoingServiceDaysCount.HasValue ? p.OnGoingServiceDaysCount.Value : 0) + (p.PriorServiceDaysCount.HasValue ? p.PriorServiceDaysCount.Value : 0),
                        ByExamResults        = (p.ByExamResult.HasValue ? p.ByExamResult.Value : 0)
                    });
                }

                // Filter record count.
                recFilterOut = iq.Count();

                // Apply pagination.
                iq = iq.Skip(startRec).Take(pageSize);
                //Get list of data
                var data = iq.ToList();

                return(data);
            }
            catch
            {
                throw;
            }
        }
Exemple #7
0
        public int UndoPreference(PromotionsRecords PromotionRecord)
        {
            try
            {
                using (var db = new HCMEntities())
                {
                    //db.Configuration.AutoDetectChangesEnabled = false;      // to increase performance

                    List <PromotionsRecordsEmployeesSeniorityDetails>   SeniorityToBeRemoved  = new List <PromotionsRecordsEmployeesSeniorityDetails>();
                    List <PromotionsRecordsEmployeesEducationsDetails>  EducationToBeRemoved  = new List <PromotionsRecordsEmployeesEducationsDetails>();
                    List <PromotionsRecordsEmployeesEvaluationsDetails> EvaluationToBeRemoved = new List <PromotionsRecordsEmployeesEvaluationsDetails>();

                    PromotionsRecordsEmployees PromotionRecordEmployeeObj;
                    PromotionsRecords          PromotionRecordObj = db.PromotionsRecords
                                                                    .Include("PromotionsRecordsEmployees")
                                                                    .Include("PromotionsRecordsEmployees.PromotionsRecordsEmployeesSeniorityDetails")
                                                                    .Include("PromotionsRecordsEmployees.PromotionsRecordsEmployeesEvaluationsDetails")
                                                                    .Include("PromotionsRecordsEmployees.PromotionsRecordsEmployeesEducationsDetails")
                                                                    .FirstOrDefault(d => d.PromotionRecordID == PromotionRecord.PromotionRecordID);
                    if (PromotionRecordObj != null && PromotionRecordObj.PromotionRecordID > 0)
                    {
                        PromotionRecordObj.PromotionRecordStatusID = PromotionRecord.PromotionRecordStatusID;
                        PromotionRecordObj.PreferenceTime          = PromotionRecord.PreferenceTime;
                        PromotionRecordObj.PreferenceBy            = PromotionRecord.PreferenceBy;
                        PromotionRecordObj.LastUpdatedBy           = PromotionRecord.LastUpdatedBy;
                        PromotionRecordObj.LastUpdatedDate         = PromotionRecord.LastUpdatedDate;
                        foreach (var Candidate in PromotionRecord.PromotionsRecordsEmployees)
                        {
                            PromotionRecordEmployeeObj = PromotionRecordObj.PromotionsRecordsEmployees.FirstOrDefault(c => c.PromotionRecordEmployeeID == Candidate.PromotionRecordEmployeeID);
                            if (PromotionRecordEmployeeObj != null && PromotionRecordEmployeeObj.PromotionRecordEmployeeID > 0)
                            {
                                PromotionRecordEmployeeObj.PromotionRecordJobVacancyID = Candidate.PromotionRecordJobVacancyID;
                                PromotionRecordEmployeeObj.EducationPoints             = Candidate.EducationPoints;
                                PromotionRecordEmployeeObj.SeniorityPoints             = Candidate.SeniorityPoints;
                                PromotionRecordEmployeeObj.EvaluationPoints            = Candidate.EducationPoints;
                                PromotionRecordEmployeeObj.ActualTaskPerformancePoints = Candidate.ActualTaskPerformancePoints;
                                PromotionRecordEmployeeObj.PriorServiceDaysCount       = Candidate.PriorServiceDaysCount;
                                PromotionRecordEmployeeObj.PromotionDecisionID         = Candidate.PromotionDecisionID;

                                // deleting PREmps Seniority
                                PromotionRecordEmployeeObj.PromotionsRecordsEmployeesSeniorityDetails.ToList()      //.RemoveAll(x => x.PromotionRecordEmployeeID == Candidate.PromotionRecordEmployeeID);
                                .ForEach(x => SeniorityToBeRemoved.Add(x));

                                // deleting PREmps Educations
                                PromotionRecordEmployeeObj.PromotionsRecordsEmployeesEducationsDetails.ToList()     //.RemoveAll(x => x.PromotionRecordEmployeeID == Candidate.PromotionRecordEmployeeID);
                                .ForEach(x => EducationToBeRemoved.Add(x));

                                // deleting PREmps Evaluations
                                PromotionRecordEmployeeObj.PromotionsRecordsEmployeesEvaluationsDetails.ToList()    //.RemoveAll(x => x.PromotionRecordEmployeeID == Candidate.PromotionRecordEmployeeID);
                                .ForEach(x => EvaluationToBeRemoved.Add(x));

                                PromotionRecordEmployeeObj.LastUpdatedBy   = PromotionRecord.LastUpdatedBy;
                                PromotionRecordEmployeeObj.LastUpdatedDate = PromotionRecord.LastUpdatedDate;
                            }
                        }

                        //db.Configuration.AutoDetectChangesEnabled = true;      // to increase performance
                        //db.ChangeTracker.DetectChanges();

                        if (SeniorityToBeRemoved.Count > 0)
                        {
                            db.PromotionsRecordsEmployeesSeniorityDetails.RemoveRange(SeniorityToBeRemoved);
                        }
                        if (EducationToBeRemoved.Count > 0)
                        {
                            db.PromotionsRecordsEmployeesEducationsDetails.RemoveRange(EducationToBeRemoved);
                        }
                        if (EvaluationToBeRemoved.Count > 0)
                        {
                            db.PromotionsRecordsEmployeesEvaluationsDetails.RemoveRange(EvaluationToBeRemoved);
                        }

                        return(db.SaveChanges());
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }
            catch
            {
                throw;
            }
        }