Exemplo n.º 1
0
        public static void Init(CrudContext context)
        {
            #region Dismissals
            var defaultDemanded = new DemandedDismissal
            {
                Title = "استحقاقی",
                DismissalSystemType        = DismissalSystemType.Default,
                DismissalType              = DismissalType.Demanded,
                DismissalExcessiveReaction = DismissalExcessiveReaction.Forbid,
                DemandedAllowanceInMonth   = (2).GetDaysInSeconds(),
                DemandedCountInMonth       = 2,
                DemandedAllowanceInYear    = (24).GetDaysInSeconds(),
                DemandedCountInYear        = 24,
                DemandedMealTimeIsIncluded = true,
                DemandedIsNationalHolidysConsideredInDismissal = true,
                DemandedIsFridaysConsideredInDismissal         = true,
                DemandedAmountOfHoursConsideredDailyDismissal  = 6
            };
            if (!context.DemandedDismissals.Any())
            {
                context.DemandedDismissals.AddOrUpdate(defaultDemanded);
            }

            var defaultSickness = new SicknessDismissal
            {
                Title = "استعلاجی",
                DismissalSystemType        = DismissalSystemType.Default,
                DismissalType              = DismissalType.Sickness,
                DismissalExcessiveReaction = DismissalExcessiveReaction.Forbid,
                SicknessAllowanceInYear    = (12).GetDaysInSeconds(),
                SicknessCountInYear        = 12,
                SicknessIsAllowedToSubtractFromDemandedDismissalAfterLimit = true
            };
            if (!context.SicknessDismissals.Any())
            {
                context.SicknessDismissals.AddOrUpdate(defaultSickness);
            }

            var defaultWithoutSalary = new WithoutSalaryDismissal
            {
                Title = "بدون حقوق",
                DismissalSystemType           = DismissalSystemType.Default,
                DismissalType                 = DismissalType.WithoutSalary,
                DismissalExcessiveReaction    = DismissalExcessiveReaction.Forbid,
                WithoutSalaryAllowanceInMonth = (5).GetDaysInSeconds(),
                WithoutSalaryCountInMonth     = 2
            };
            if (!context.WithoutSalaryDismissals.Any())
            {
                context.WithoutSalaryDismissals.AddOrUpdate(defaultWithoutSalary);
            }

            var defaultEncouragement = new EncouragementDismissal
            {
                Title = "تشویقی",
                DismissalSystemType                = DismissalSystemType.Default,
                DismissalType                      = DismissalType.Encouragement,
                DismissalExcessiveReaction         = DismissalExcessiveReaction.Forbid,
                EncouragementFromDate              = DateTime.Now.AddDays(-2).Date,
                EncouragementToDate                = DateTime.Now.Date,
                EncouragementConsiderWithoutSalary = true
            };
            if (!context.EncouragementDismissals.Any())
            {
                context.EncouragementDismissals.AddOrUpdate(defaultEncouragement);
            }

            var defaultMarriage = new MarriageDismissal
            {
                Title = "ازدواج",
                DismissalSystemType           = DismissalSystemType.Default,
                DismissalType                 = DismissalType.Marriage,
                DismissalExcessiveReaction    = DismissalExcessiveReaction.Forbid,
                MarriageAllowanceInTotal      = (20).GetDaysInSeconds(),
                MarriageCountInTotal          = 1,
                MarriageConsiderWithoutSalary = true,
                MarriageIsAllowedToSubtractFromDemandedDismissalAfterLimit = true
            };
            if (!context.MarriageDismissals.Any())
            {
                context.MarriageDismissals.AddOrUpdate(defaultMarriage);
            }

            var defaultChildBirth = new ChildBirthDismissal
            {
                Title = "زایمان",
                DismissalSystemType             = DismissalSystemType.Default,
                DismissalType                   = DismissalType.ChildBirth,
                DismissalExcessiveReaction      = DismissalExcessiveReaction.Forbid,
                ChildBirthAllowanceInTotal      = (180).GetDaysInSeconds(),
                ChildBirthConsiderWithoutSalary = false,
                ChildBirthIsAllowedToSubtractFromDemandedDismissalAfterLimit = true
            };
            if (!context.ChildBirthDismissals.Any())
            {
                context.ChildBirthDismissals.AddOrUpdate(defaultChildBirth);
            }

            var defaultBreastFeeding = new BreastFeedingDismissal
            {
                Title = "شیردهی",
                DismissalSystemType           = DismissalSystemType.Default,
                DismissalType                 = DismissalType.BreastFeeding,
                DismissalExcessiveReaction    = DismissalExcessiveReaction.Forbid,
                BreastFeedingAllowanceInTotal = (20).GetDaysInSeconds(),
                BreastFeedingAllowanceInDay   = (3).GetHoursInSeconds(),
                BreastFeedingCountInDay       = 2,
                BreastFeedingIsAllowedToSubtractFromDemandedDismissalAfterLimit = true
            };
            if (!context.BreastFeedingDismissals.Any())
            {
                context.BreastFeedingDismissals.AddOrUpdate(defaultBreastFeeding);
            }

            var defaultDeathOfRelatives = new DeathOfRelativesDismissal
            {
                Title = "فوت بستگان",
                DismissalSystemType              = DismissalSystemType.Default,
                DismissalType                    = DismissalType.DeathOfRelatives,
                DismissalExcessiveReaction       = DismissalExcessiveReaction.Forbid,
                DeathOfRelativesAllowanceInTotal = (20).GetDaysInSeconds(),
                DeathOfRelativesIsAllowedToSubtractFromDemandedDismissalAfterLimit = true
            };
            if (!context.DeathOfRelativesDismissals.Any())
            {
                context.DeathOfRelativesDismissals.AddOrUpdate(defaultDeathOfRelatives);
            }
            #endregion

            #region Duties
            var duties = new List <Duty>
            {
                new Duty
                {
                    Title = "دورن شهری"
                },
                new Duty
                {
                    Title = "بیرون شهری"
                }
            };
            if (!context.Duties.Any())
            {
                duties.ForEach(i => context.Duties.AddOrUpdate(i));
            }
            #endregion

            context.SaveChanges();

            #region personnel
            var workUnits = new List <WorkUnit>
            {
                new WorkUnit
                {
                    Title = "فروش"
                },
                new WorkUnit
                {
                    Title = "فنی"
                }
            };
            if (!context.WorkUnits.Any())
            {
                workUnits.ForEach(i => context.WorkUnits.AddOrUpdate(i));
            }

            context.SaveChanges();

            var groupCategories = new List <GroupCategory>
            {
                new GroupCategory
                {
                    Title = "فروش"
                },
                new GroupCategory
                {
                    Title = "مدیران"
                }
            };
            if (!context.GroupCategories.Any())
            {
                groupCategories.ForEach(i => context.GroupCategories.AddOrUpdate(i));
            }

            var employeementTypes = new List <EmployeementType>
            {
                new EmployeementType
                {
                    Title = "فروش"
                },
                new EmployeementType
                {
                    Title = "فنی"
                }
            };
            if (!context.EmployeementTypes.Any())
            {
                employeementTypes.ForEach(i => context.EmployeementTypes.AddOrUpdate(i));
            }

            var positions = new List <Position>
            {
                new Position
                {
                    WorkUnitId = 1,
                    Title      = "مدیر فروش"
                },
                new Position
                {
                    WorkUnitId = 1,
                    Title      = "مسئول فروش"
                },
                new Position
                {
                    WorkUnitId = 2,
                    Title      = "مدیر فنی"
                },
                new Position
                {
                    WorkUnitId = 2,
                    Title      = "برنامه نویس"
                }
            };
            if (!context.Positions.Any())
            {
                positions.ForEach(i => context.Positions.AddOrUpdate(i));
            }

            context.SaveChanges();

            var personnel1 = new Personnel
            {
                Code                        = "1",
                Name                        = "آرش",
                LastName                    = "ساسانی",
                FathersName                 = "مصطفی",
                NationalCode                = "1234567890",
                BirthCerficiateCode         = "123123123",
                PlaceOfBirth                = "تهران",
                State                       = "تهران",
                City                        = "تهران",
                PostalCode                  = "123123123",
                BirthDate                   = DateTime.Now.AddYears(-29),
                Email                       = "*****@*****.**",
                Mobile                      = "09128027821",
                Phone                       = "44223344",
                Address                     = "تهران خ الف",
                Education                   = Education.Bachelor,
                MilitaryServiceStatus       = MilitaryServiceStatus.Completed,
                Gender                      = Gender.Male,
                MaritalStatus               = MaritalStatus.Single,
                GroupCategoryId             = 1,
                EmployeementTypeId          = 1,
                PositionId                  = 1,
                InsuranceRecordDuration     = "2 ماه",
                NoneInsuranceRecordDuration = "2 سال",
                BankAccountNumber           = "12312a123c",
                DateOfEmployeement          = DateTime.Now.AddYears(-2),
                FirstDateOfWork             = DateTime.Now.AddYears(-2).AddDays(2),
                ActiveState                 = ActiveState.Active,
                IsPresent                   = true
            };
            var personnel2 = new Personnel
            {
                Code                        = "2",
                Name                        = "ساناز",
                LastName                    = "محمدی",
                FathersName                 = "محمد",
                NationalCode                = "1212567820",
                BirthCerficiateCode         = "1231234333",
                PlaceOfBirth                = "تهران",
                State                       = "تهران",
                City                        = "تهران",
                PostalCode                  = "125623123",
                BirthDate                   = DateTime.Now.AddYears(-39),
                Email                       = "*****@*****.**",
                Mobile                      = "09123457821",
                Phone                       = "4422334544",
                Address                     = "تهران خ الف",
                Education                   = Education.Phd,
                MilitaryServiceStatus       = null,
                Gender                      = Gender.Female,
                MaritalStatus               = MaritalStatus.Married,
                GroupCategoryId             = 2,
                EmployeementTypeId          = 2,
                PositionId                  = 2,
                InsuranceRecordDuration     = "2 ماه",
                NoneInsuranceRecordDuration = "2 سال",
                BankAccountNumber           = "12312a123c",
                DateOfEmployeement          = DateTime.Now.AddYears(-3),
                FirstDateOfWork             = DateTime.Now.AddYears(-3).AddDays(2),
                ActiveState                 = ActiveState.Active,
                IsPresent                   = true
            };
            if (!context.Personnel.Any())
            {
                context.Personnel.AddOrUpdate(personnel1);
                context.Personnel.AddOrUpdate(personnel2);
            }
            #endregion

            context.SaveChanges();

            #region Personnel Logs
            var personnelLogs = new List <PersonnelLog>
            {
                new PersonnelLog
                {
                    PersonnelId      = 1,
                    LogDate          = DateTime.Now.AddDays(-1),
                    SubmittedDate    = DateTime.Now.AddDays(-1),
                    DeviceId         = 1,
                    IsFingerEntrance = true,
                    FingerNo         = 0
                }
                , new PersonnelLog
                {
                    PersonnelId    = 1,
                    LogDate        = DateTime.Now.AddDays(-2),
                    SubmittedDate  = DateTime.Now.AddDays(-2).AddMinutes(8),
                    DeviceId       = 1,
                    IsFaceEntrance = true
                }
                , new PersonnelLog
                {
                    PersonnelId    = 1,
                    LogDate        = DateTime.Now.AddDays(-3),
                    SubmittedDate  = DateTime.Now.AddDays(-3).AddMinutes(8),
                    DeviceId       = 1,
                    IsCardEntrance = true
                },
                new PersonnelLog
                {
                    PersonnelId      = 2,
                    LogDate          = DateTime.Now.AddDays(-1).AddMinutes(8),
                    SubmittedDate    = DateTime.Now.AddDays(-1).AddMinutes(8),
                    DeviceId         = 1,
                    IsFingerEntrance = true,
                    FingerNo         = 0
                }
                , new PersonnelLog
                {
                    PersonnelId    = 2,
                    LogDate        = DateTime.Now.AddDays(-2),
                    SubmittedDate  = DateTime.Now.AddDays(-2).AddMinutes(8),
                    DeviceId       = 1,
                    IsFaceEntrance = true
                }
                , new PersonnelLog
                {
                    PersonnelId    = 2,
                    LogDate        = DateTime.Now.AddDays(-3),
                    SubmittedDate  = DateTime.Now.AddDays(-3).AddMinutes(8),
                    DeviceId       = 1,
                    IsCardEntrance = true
                }
            };
            if (!context.PersonnelLogs.Any())
            {
                personnelLogs.ForEach(i => context.PersonnelLogs.AddOrUpdate(i));
            }
            #endregion

            #region Dismissal Approvals
            //var dismissalsApprovals = new List<DismissalApproval>
            //{
            //    new DismissalApproval
            //    {
            //        PersonnelId = 1,
            //        DismissalId = 1
            //    },
            //    new DismissalApproval
            //    {
            //        PersonnelId = 1,
            //        DismissalId = 2
            //    }
            //};
            //if (!context.DismissalsApprovals.Any())
            //    dismissalsApprovals.ForEach(i => context.DismissalsApprovals.AddOrUpdate(i));
            #endregion

            #region Duty Approvals
            var dutiesApprovals = new List <DutyApproval>
            {
                new DutyApproval
                {
                    PersonnelId = 1,
                    DutyId      = 1,
                },
                new DutyApproval
                {
                    PersonnelId = 1,
                    DutyId      = 2
                }
            };
            if (!context.DutiesApprovals.Any())
            {
                dutiesApprovals.ForEach(i => context.DutiesApprovals.AddOrUpdate(i));
            }
            #endregion

            #region Personnel Dismissals
            var dailyPersonnelDismissal = new PersonnelDailyDismissal
            {
                PersonnelId       = 1,
                DismissalId       = 1,
                SubmittedDate     = DateTime.Now.AddDays(-2),
                DismissalDuration = RequestDuration.Daily,
                ActionDate        = DateTime.Now,
                RequestAction     = RequestAction.Accept,
                FromDate          = DateTime.Now.AddDays(-1).Date,
                ToDate            = DateTime.Now.Date
            };
            if (!context.PersonnelDailyDismissals.Any())
            {
                context.PersonnelDailyDismissals.AddOrUpdate(dailyPersonnelDismissal);
            }
            var hourlyPersonnelDismissal = new PersonnelHourlyDismissal
            {
                PersonnelId       = 1,
                DismissalId       = 1,
                SubmittedDate     = DateTime.Now.AddDays(-1),
                DismissalDuration = RequestDuration.Hourly,
                ActionDate        = DateTime.Now,
                RequestAction     = RequestAction.Reject,
                Date     = DateTime.Now.Date,
                FromTime = TimeSpan.Parse("12:00:00"),
                ToTime   = TimeSpan.Parse("14:00:00")
            };
            if (!context.PersonnelHourlyDismissals.Any())
            {
                context.PersonnelHourlyDismissals.AddOrUpdate(hourlyPersonnelDismissal);
            }
            #endregion

            #region Personnel Duties
            var dailyPersonnelDuty = new PersonnelDailyDuty
            {
                PersonnelId   = 1,
                DutyId        = 1,
                SubmittedDate = DateTime.Now.AddDays(-2),
                DutyDuration  = RequestDuration.Daily,
                ActionDate    = DateTime.Now,
                RequestAction = RequestAction.Accept,
                FromDate      = DateTime.Now.AddDays(-1).Date,
                ToDate        = DateTime.Now.Date
            };
            if (!context.PersonnelDailyDuties.Any())
            {
                context.PersonnelDailyDuties.AddOrUpdate(dailyPersonnelDuty);
            }
            var hourlyPersonnelDuty = new PersonnelHourlyDuty
            {
                PersonnelId   = 1,
                DutyId        = 1,
                SubmittedDate = DateTime.Now.AddDays(-1),
                DutyDuration  = RequestDuration.Hourly,
                ActionDate    = DateTime.Now,
                RequestAction = RequestAction.Reject,
                Date          = DateTime.Now.Date,
                FromTime      = TimeSpan.Parse("12:00:00"),
                ToTime        = TimeSpan.Parse("14:00:00")
            };
            if (!context.PersonnelHourlyDuties.Any())
            {
                context.PersonnelHourlyDuties.AddOrUpdate(hourlyPersonnelDuty);
            }
            #endregion

            #region Shifts and Working Hours
            var shifts = new List <Shift>
            {
                new Shift
                {
                    Title = "شیفت نگهبانی"
                }
            };
            if (!context.Shifts.Any())
            {
                shifts.ForEach(i => context.Shifts.AddOrUpdate(i));
            }
            context.SaveChanges();

            var workingHours = new List <WorkingHour>
            {
                new WorkingHour
                {
                    ShiftId               = 1,
                    Title                 = "ساعت کاری اول",
                    FromTime              = TimeSpan.Parse("12:00"),
                    ToTime                = TimeSpan.Parse("14:00"),
                    WorkingHourDuration   = WorkingHourDuration.OneDay,
                    DailyDelay            = (2).GetHoursInSeconds(),
                    MonthlyDelay          = (12).GetHoursInSeconds(),
                    DelayPolicy           = DelayPolicy.DailyLimit,
                    DailyRush             = (2).GetHoursInSeconds(),
                    MonthlyRush           = (12).GetHoursInSeconds(),
                    RushPolicy            = RushPolicy.DailyLimit,
                    PriorExtraWorkTime    = (2).GetHoursInSeconds(),
                    LaterExtraWorkTime    = (1).GetHoursInSeconds(),
                    FloatingTime          = (6).GetHoursInSeconds(),
                    MealTimeBreakFromTime = TimeSpan.Parse("12:00:00"),
                    MealTimeBreakToTime   = TimeSpan.Parse("13:00:00")
                },
                new WorkingHour
                {
                    ShiftId               = 1,
                    Title                 = "ساعت کاری دوم",
                    FromTime              = TimeSpan.Parse("18:00"),
                    ToTime                = TimeSpan.Parse("22:00"),
                    WorkingHourDuration   = WorkingHourDuration.OneDay,
                    DailyDelay            = (2).GetHoursInSeconds(),
                    MonthlyDelay          = (12).GetHoursInSeconds(),
                    DelayPolicy           = DelayPolicy.DailyLimit,
                    DailyRush             = (2).GetHoursInSeconds(),
                    MonthlyRush           = (12).GetHoursInSeconds(),
                    RushPolicy            = RushPolicy.DailyLimit,
                    PriorExtraWorkTime    = (2).GetHoursInSeconds(),
                    LaterExtraWorkTime    = (1).GetHoursInSeconds(),
                    FloatingTime          = (6).GetHoursInSeconds(),
                    MealTimeBreakFromTime = TimeSpan.Parse("19:00:00"),
                    MealTimeBreakToTime   = TimeSpan.Parse("20:00:00")
                }
            };
            if (!context.WorkingHours.Any())
            {
                workingHours.ForEach(i => context.WorkingHours.AddOrUpdate(i));
            }
            context.SaveChanges();

            //var workingHourBreaks = new List<WorkingHourBreak>
            //{
            //    new WorkingHourBreak
            //    {
            //        WorkingHourId = 1,
            //        FromTime = TimeSpan.Parse("14:00:00"),
            //        ToTime = TimeSpan.Parse("15:00:00")
            //    },
            //    new WorkingHourBreak
            //    {
            //        WorkingHourId = 2,
            //        FromTime = TimeSpan.Parse("22:00:00"),
            //        ToTime = TimeSpan.Parse("23:00:00")
            //    }
            //};
            //context.WorkingHourBreaks.AddRange(workingHourBreaks);

            #endregion

            context.SaveChanges();

            #region Personnel Shift
            var personnelShifts = new List <PersonnelShift>
            {
                new PersonnelShift
                {
                    PersonnelId  = 1,
                    ShiftId      = 1,
                    DateAssigned = DateTime.Now
                },
                new PersonnelShift
                {
                    PersonnelId  = 2,
                    ShiftId      = 1,
                    DateAssigned = DateTime.Now.AddDays(-2)
                }
            };
            if (!context.PersonnelShifts.Any())
            {
                personnelShifts.ForEach(i => context.PersonnelShifts.AddOrUpdate(i));
            }
            #endregion

            context.SaveChanges();

            #region Personnel Shift Assignments
            var shiftAssignDates = new List <PersonnelShiftAssignment>
            {
                new PersonnelShiftAssignment
                {
                    PersonnelShiftId = 1,
                    Date             = DateTime.Now.Date.AddDays(10)
                },
                new PersonnelShiftAssignment
                {
                    PersonnelShiftId = 2,
                    Date             = DateTime.Now.Date.AddDays(12)
                }
            };
            if (!context.PersonnelShiftAssignments.Any())
            {
                shiftAssignDates.ForEach(i => context.PersonnelShiftAssignments.AddOrUpdate(i));
            }
            #endregion

            #region Personnel Shift Replacements
            var shiftReplacements = new List <PersonnelShiftReplacement>
            {
                new PersonnelShiftReplacement
                {
                    PersonnelId           = 1,
                    ReplacedPersonnelId   = 2,
                    WorkingHourId         = 1,
                    ReplacedWorkingHourId = 1,
                    RequestedDate         = DateTime.Now.AddDays(-2),
                    ActionDate            = DateTime.Now.AddDays(-1),
                    ReplacementDate       = DateTime.Now.AddDays(-1),
                    RequestAction         = RequestAction.Accept
                },
                new PersonnelShiftReplacement
                {
                    PersonnelId           = 1,
                    ReplacedPersonnelId   = 2,
                    WorkingHourId         = 2,
                    ReplacedWorkingHourId = 2,
                    RequestedDate         = DateTime.Now.AddDays(-1),
                    ActionDate            = DateTime.Now,
                    ReplacementDate       = DateTime.Now,
                    RequestAction         = RequestAction.Accept
                },
            };
            if (!context.PersonnelShiftReplacements.Any())
            {
                shiftReplacements.ForEach(i => context.PersonnelShiftReplacements.AddOrUpdate(i));
            }
            #endregion

            #region Approval Procs
            var approvalProc1 = new ApprovalProc
            {
                ParentId         = null,
                Title            = "تایید کننده 1",
                FirstPriorityId  = 1,
                SecondPriorityId = 2,
                ThirdPriorityId  = null,
                ActiveState      = ActiveState.Active
            };
            var approvalProc2 = new ApprovalProc
            {
                ParentId         = 1,
                Title            = "تایید کننده 2",
                FirstPriorityId  = 2,
                SecondPriorityId = null,
                ThirdPriorityId  = null,
                ActiveState      = ActiveState.Active
            };
            if (!context.ApprovalProcs.Any())
            {
                context.ApprovalProcs.AddOrUpdate(approvalProc1);
                context.SaveChanges();
                context.ApprovalProcs.AddOrUpdate(approvalProc2);
            }

            //personnel1.DismissalApprovalProcId = 1;
            //personnel1.DutyApprovalProcId = 1;
            //personnel1.ShiftReplacementProcId = 1;
            //personnel2.DismissalApprovalProcId = 2;
            //personnel2.DutyApprovalProcId = 2;
            //personnel2.ShiftReplacementProcId = 2;
            //context.SaveChanges();
            #endregion

            #region Calendar Dates
            //get shamsi and hijri holidays for the next 10 years
            var now = DateTime.Now;
            for (var date = now.AddYears(-1); date <= now.AddYears(10);
                 date = date.AddYears(1))
            {
                SetupCalendarDates(context, date);
            }
            #endregion

            #region Adjustments And Ratios
            var adjustments = new List <Adjustment>
            {
                new Adjustment
                {
                    ShiftId            = 1,
                    Title              = "تهاتر 1",
                    AdjustmentType1    = AdjustmentType.Rush,
                    AdjustmentType2    = AdjustmentType.ExtraWork,
                    AdjustmentPriority = AdjustmentPriority.BeforeRatio
                },
                new Adjustment
                {
                    ShiftId            = 1,
                    Title              = "تهاتر 2",
                    AdjustmentType1    = AdjustmentType.Rush,
                    AdjustmentType2    = AdjustmentType.ExtraWork,
                    AdjustmentPriority = AdjustmentPriority.BeforeRatio
                }
            };
            if (!context.Adjustments.Any())
            {
                adjustments.ForEach(i => context.Adjustments.AddOrUpdate(i));
            }

            var ratios = new List <Ratio>
            {
                new Ratio
                {
                    ShiftId       = 1,
                    RatioType     = RatioType.Delay,
                    Amount        = 2,
                    FromTime      = TimeSpan.Parse("12:00:00"),
                    ToTime        = TimeSpan.Parse("14:00:00"),
                    AddedConstant = (30).GetMinutesInSeconds(),
                    HasStep       = true
                },
                new Ratio
                {
                    ShiftId       = 1,
                    RatioType     = RatioType.Rush,
                    Amount        = 2,
                    FromTime      = TimeSpan.Parse("11:00:00"),
                    ToTime        = TimeSpan.Parse("13:00:00"),
                    AddedConstant = (40).GetMinutesInSeconds(),
                    HasStep       = false
                }
            };
            if (!context.Ratios.Any())
            {
                ratios.ForEach(i => context.Ratios.AddOrUpdate(i));
            }

            context.SaveChanges();
            #endregion

            #region Devices
            var devices = new List <Device>
            {
                new Device
                {
                    DeviceId     = 1,
                    DeviceType   = "Finger",
                    Model        = "Finger",
                    SerialNumber = "123",
                    ActiveState  = ActiveState.Active
                },
                new Device
                {
                    DeviceId     = 2,
                    DeviceType   = "Face",
                    Model        = "Face",
                    SerialNumber = "123",
                    ActiveState  = ActiveState.Deactive
                }
            };
            if (!context.Devices.Any())
            {
                devices.ForEach(i => context.Devices.AddOrUpdate(i));
            }
            #endregion
        }
Exemplo n.º 2
0
        protected override void Seed(UberContext context)
        {
            #region Dismissals
            var defaultDemanded = new DemandedDismissal
            {
                Title = "Demanded",
                DismissalSystemType        = DismissalSystemType.Default,
                DismissalType              = DismissalType.Demanded,
                DismissalExcessiveReaction = DismissalExcessiveReaction.Forbid,
                DemandedAllowanceInMonth   = (2).GetDaysInSeconds(),
                DemandedCountInMonth       = 2,
                DemandedAllowanceInYear    = (24).GetDaysInSeconds(),
                DemandedCountInYear        = 24,
                DemandedMealTimeIsIncluded = true,
                DemandedIsNationalHolidysConsideredInDismissal = true,
                DemandedIsFridaysConsideredInDismissal         = true,
                DemandedAmountOfHoursConsideredDailyDismissal  = 6
            };
            context.DemandedDismissals.Add(defaultDemanded);

            var defaultSickness = new SicknessDismissal
            {
                Title = "Sickness",
                DismissalSystemType        = DismissalSystemType.Default,
                DismissalType              = DismissalType.Sickness,
                DismissalExcessiveReaction = DismissalExcessiveReaction.Forbid,
                SicknessAllowanceInYear    = (12).GetDaysInSeconds(),
                SicknessCountInYear        = 12,
                SicknessIsAllowedToSubtractFromDemandedDismissalAfterLimit = true
            };
            context.SicknessDismissals.Add(defaultSickness);

            var defaultWithoutSalary = new WithoutSalaryDismissal
            {
                Title = "Without Salary",
                DismissalSystemType           = DismissalSystemType.Default,
                DismissalType                 = DismissalType.WithoutSalary,
                DismissalExcessiveReaction    = DismissalExcessiveReaction.Forbid,
                WithoutSalaryAllowanceInMonth = (5).GetDaysInSeconds(),
                WithoutSalaryCountInMonth     = 2
            };
            context.WithoutSalaryDismissals.Add(defaultWithoutSalary);

            var defaultEncouragement = new EncouragementDismissal
            {
                Title = "Encouragement",
                DismissalSystemType                = DismissalSystemType.Default,
                DismissalType                      = DismissalType.Encouragement,
                DismissalExcessiveReaction         = DismissalExcessiveReaction.Forbid,
                EncouragementFromDate              = DateTime.Now.AddDays(-2).Date,
                EncouragementToDate                = DateTime.Now.Date,
                EncouragementConsiderWithoutSalary = true
            };
            context.EncouragementDismissals.Add(defaultEncouragement);

            var defaultMarriage = new MarriageDismissal
            {
                Title = "Marriage",
                DismissalSystemType           = DismissalSystemType.Default,
                DismissalType                 = DismissalType.Marriage,
                DismissalExcessiveReaction    = DismissalExcessiveReaction.Forbid,
                MarriageAllowanceInTotal      = (20).GetDaysInSeconds(),
                MarriageCountInTotal          = 1,
                MarriageConsiderWithoutSalary = true,
                MarriageIsAllowedToSubtractFromDemandedDismissalAfterLimit = true
            };
            context.MarriageDismissals.Add(defaultMarriage);

            var defaultChildBirth = new ChildBirthDismissal
            {
                Title = "Child Birth",
                DismissalSystemType             = DismissalSystemType.Default,
                DismissalType                   = DismissalType.ChildBirth,
                DismissalExcessiveReaction      = DismissalExcessiveReaction.Forbid,
                ChildBirthAllowanceInTotal      = (180).GetDaysInSeconds(),
                ChildBirthConsiderWithoutSalary = false,
                ChildBirthIsAllowedToSubtractFromDemandedDismissalAfterLimit = true
            };
            context.ChildBirthDismissals.Add(defaultChildBirth);

            var defaultBreastFeeding = new BreastFeedingDismissal
            {
                Title = "Breast Feeding",
                DismissalSystemType           = DismissalSystemType.Default,
                DismissalType                 = DismissalType.BreastFeeding,
                DismissalExcessiveReaction    = DismissalExcessiveReaction.Forbid,
                BreastFeedingAllowanceInTotal = (20).GetDaysInSeconds(),
                BreastFeedingAllowanceInDay   = (3).GetHoursInSeconds(),
                BreastFeedingCountInDay       = 2,
                BreastFeedingIsAllowedToSubtractFromDemandedDismissalAfterLimit = true
            };
            context.BreastFeedingDismissals.Add(defaultBreastFeeding);

            var defaultDeathOfRelatives = new DeathOfRelativesDismissal
            {
                Title = "Death of Relatives",
                DismissalSystemType              = DismissalSystemType.Default,
                DismissalType                    = DismissalType.DeathOfRelatives,
                DismissalExcessiveReaction       = DismissalExcessiveReaction.Forbid,
                DeathOfRelativesAllowanceInTotal = (20).GetDaysInSeconds(),
                DeathOfRelativesIsAllowedToSubtractFromDemandedDismissalAfterLimit = true
            };
            context.DeathOfRelativesDismissals.Add(defaultDeathOfRelatives);
            #endregion

            #region Duties
            var duties = new List <Duty>
            {
                new Duty
                {
                    Title = "Domestic"
                },
                new Duty
                {
                    Title = "International"
                }
            };
            context.Duties.AddRange(duties);
            #endregion

            context.SaveChanges();

            #region personnel
            var workUnits = new List <WorkUnit>
            {
                new WorkUnit
                {
                    Title = "Sales department"
                },
                new WorkUnit
                {
                    Title = "Engineering department"
                }
            };
            context.WorkUnits.AddRange(workUnits);

            context.SaveChanges();

            var groupCategories = new List <GroupCategory>
            {
                new GroupCategory
                {
                    Title = "Sales"
                },
                new GroupCategory
                {
                    Title = "Managers"
                }
            };
            context.GroupCategories.AddRange(groupCategories);
            var employeemntTypes = new List <EmployeementType>
            {
                new EmployeementType
                {
                    Title = "Sales"
                },
                new EmployeementType
                {
                    Title = "Engineering"
                }
            };
            context.EmployeementTypes.AddRange(employeemntTypes);
            var positions = new List <Position>
            {
                new Position
                {
                    WorkUnitId = 1,
                    Title      = "CFO"
                },
                new Position
                {
                    WorkUnitId = 1,
                    Title      = "Sales VP"
                },
                new Position
                {
                    WorkUnitId = 2,
                    Title      = "CEO"
                },
                new Position
                {
                    WorkUnitId = 2,
                    Title      = "Engineer"
                }
            };
            context.Positions.AddRange(positions);

            context.SaveChanges();

            var personnel1 = new Personnel
            {
                Code                        = "1",
                Name                        = "Arash",
                LastName                    = "Sasani",
                FathersName                 = "Arash",
                NationalCode                = "1234567890",
                BirthCertificateCode        = "123123123",
                PlaceOfBirth                = "Tehran",
                State                       = "Tehran",
                City                        = "Tehran",
                PostalCode                  = "123123123",
                BirthDate                   = DateTime.Now.AddYears(-29),
                Email                       = "*****@*****.**",
                Mobile                      = "09128027821",
                Phone                       = "44223344",
                Address                     = "Some place",
                Education                   = Education.Bachelor,
                MilitaryServiceStatus       = MilitaryServiceStatus.Completed,
                Gender                      = Gender.Male,
                MaritalStatus               = MaritalStatus.Single,
                GroupCategoryId             = 1,
                EmployeementTypeId          = 1,
                PositionId                  = 1,
                InsuranceRecordDuration     = "2 months",
                NoneInsuranceRecordDuration = "2 years",
                BankAccountNumber           = "12312a123c",
                DateOfEmployeement          = DateTime.Now.AddYears(-2),
                FirstDateOfWork             = DateTime.Now.AddYears(-2).AddDays(2),
                ActiveState                 = ActiveState.Active,
                IsPresent                   = true
            };
            var personnel2 = new Personnel
            {
                Code                        = "2",
                Name                        = "John",
                LastName                    = "Doe",
                FathersName                 = "John",
                NationalCode                = "1212567820",
                BirthCertificateCode        = "1231234333",
                PlaceOfBirth                = "LA",
                State                       = "LA",
                City                        = "LA",
                PostalCode                  = "125623123",
                BirthDate                   = DateTime.Now.AddYears(-39),
                Email                       = "*****@*****.**",
                Mobile                      = "09123457821",
                Phone                       = "4422334544",
                Address                     = "Some place",
                Education                   = Education.Phd,
                MilitaryServiceStatus       = null,
                Gender                      = Gender.Female,
                MaritalStatus               = MaritalStatus.Married,
                GroupCategoryId             = 2,
                EmployeementTypeId          = 2,
                PositionId                  = 2,
                InsuranceRecordDuration     = "2 months",
                NoneInsuranceRecordDuration = "2 years",
                BankAccountNumber           = "12312a123c",
                DateOfEmployeement          = DateTime.Now.AddYears(-3),
                FirstDateOfWork             = DateTime.Now.AddYears(-3).AddDays(2),
                ActiveState                 = ActiveState.Active,
                IsPresent                   = true
            };
            context.Personnel.Add(personnel1);
            context.Personnel.Add(personnel2);
            #endregion

            context.SaveChanges();

            #region Duty Approvals
            var dutiesApprovals = new List <DutyApproval>
            {
                new DutyApproval
                {
                    PersonnelId = 1,
                    DutyId      = 1,
                },
                new DutyApproval
                {
                    PersonnelId = 1,
                    DutyId      = 2
                }
            };
            context.DutiesApprovals.AddRange(dutiesApprovals);
            #endregion

            #region Personnel Dismissals
            var dailyPersonnelDismissal = new PersonnelDailyDismissal
            {
                PersonnelId       = 1,
                DismissalId       = 1,
                SubmittedDate     = DateTime.Now.AddDays(-2),
                DismissalDuration = RequestDuration.Daily,
                ActionDate        = DateTime.Now,
                RequestAction     = RequestAction.Accept,
                FromDate          = DateTime.Now.AddDays(-1).Date,
                ToDate            = DateTime.Now.Date
            };
            context.PersonnelDailyDismissals.Add(dailyPersonnelDismissal);
            var hourlyPersonnelDismissal = new PersonnelHourlyDismissal
            {
                PersonnelId       = 1,
                DismissalId       = 1,
                SubmittedDate     = DateTime.Now.AddDays(-1),
                DismissalDuration = RequestDuration.Hourly,
                ActionDate        = DateTime.Now,
                RequestAction     = RequestAction.Reject,
                Date     = DateTime.Now.Date,
                FromTime = TimeSpan.Parse("12:00:00"),
                ToTime   = TimeSpan.Parse("14:00:00")
            };
            context.PersonnelHourlyDismissals.Add(hourlyPersonnelDismissal);
            #endregion

            #region Personnel Duties
            var dailyPersonnelDuty = new PersonnelDailyDuty
            {
                PersonnelId   = 1,
                DutyId        = 1,
                SubmittedDate = DateTime.Now.AddDays(-2),
                DutyDuration  = RequestDuration.Daily,
                ActionDate    = DateTime.Now,
                RequestAction = RequestAction.Accept,
                FromDate      = DateTime.Now.AddDays(-1).Date,
                ToDate        = DateTime.Now.Date
            };
            context.PersonnelDailyDuties.Add(dailyPersonnelDuty);
            var hourlyPersonnelDuty = new PersonnelHourlyDuty
            {
                PersonnelId   = 1,
                DutyId        = 1,
                SubmittedDate = DateTime.Now.AddDays(-1),
                DutyDuration  = RequestDuration.Hourly,
                ActionDate    = DateTime.Now,
                RequestAction = RequestAction.Reject,
                Date          = DateTime.Now.Date,
                FromTime      = TimeSpan.Parse("12:00:00"),
                ToTime        = TimeSpan.Parse("14:00:00")
            };
            context.PersonnelHourlyDuties.Add(hourlyPersonnelDuty);
            #endregion

            #region Shifts and Working Hours
            var shifts = new List <Shift>
            {
                new Shift
                {
                    Title = "Employment"
                },
                new Shift
                {
                    Title = "Management"
                }
            };
            context.Shifts.AddRange(shifts);
            context.SaveChanges();

            var workingHours = new List <WorkingHour>
            {
                new WorkingHour
                {
                    ShiftId               = 1,
                    Title                 = "Working hour 1",
                    FromTime              = TimeSpan.Parse("8:00"),
                    ToTime                = TimeSpan.Parse("17:00"),
                    WorkingHourDuration   = WorkingHourDuration.OneDay,
                    DailyDelay            = (0).GetHoursInSeconds(),
                    MonthlyDelay          = (0).GetHoursInSeconds(),
                    DailyRush             = (0).GetHoursInSeconds(),
                    MonthlyRush           = (0).GetHoursInSeconds(),
                    PriorExtraWorkTime    = (1).GetHoursInSeconds(),
                    LaterExtraWorkTime    = (1).GetHoursInSeconds(),
                    FloatingTime          = (0).GetHoursInSeconds(),
                    MealTimeBreakFromTime = null,
                    MealTimeBreakToTime   = null
                },
                new WorkingHour
                {
                    ShiftId               = 2,
                    Title                 = "Working hour 1",
                    FromTime              = TimeSpan.Parse("12:00"),
                    ToTime                = TimeSpan.Parse("14:00"),
                    WorkingHourDuration   = WorkingHourDuration.OneDay,
                    DailyDelay            = (2).GetHoursInSeconds(),
                    MonthlyDelay          = (12).GetHoursInSeconds(),
                    DailyRush             = (2).GetHoursInSeconds(),
                    MonthlyRush           = (12).GetHoursInSeconds(),
                    PriorExtraWorkTime    = (2).GetHoursInSeconds(),
                    LaterExtraWorkTime    = (1).GetHoursInSeconds(),
                    FloatingTime          = (6).GetHoursInSeconds(),
                    MealTimeBreakFromTime = TimeSpan.Parse("12:00:00"),
                    MealTimeBreakToTime   = TimeSpan.Parse("13:00:00")
                },
                new WorkingHour
                {
                    ShiftId               = 2,
                    Title                 = "Working hour 2",
                    FromTime              = TimeSpan.Parse("18:00"),
                    ToTime                = TimeSpan.Parse("22:00"),
                    WorkingHourDuration   = WorkingHourDuration.OneDay,
                    DailyDelay            = (2).GetHoursInSeconds(),
                    MonthlyDelay          = (12).GetHoursInSeconds(),
                    DailyRush             = (2).GetHoursInSeconds(),
                    MonthlyRush           = (12).GetHoursInSeconds(),
                    PriorExtraWorkTime    = (2).GetHoursInSeconds(),
                    LaterExtraWorkTime    = (1).GetHoursInSeconds(),
                    FloatingTime          = (6).GetHoursInSeconds(),
                    MealTimeBreakFromTime = TimeSpan.Parse("19:00:00"),
                    MealTimeBreakToTime   = TimeSpan.Parse("20:00:00")
                }
            };
            context.WorkingHours.AddRange(workingHours);
            context.SaveChanges();

            #endregion

            context.SaveChanges();

            #region Personnel Shift
            var personnelShifts = new List <PersonnelShift>
            {
                new PersonnelShift
                {
                    PersonnelId  = 1,
                    ShiftId      = 1,
                    DateAssigned = DateTime.Now
                },
                new PersonnelShift
                {
                    PersonnelId  = 2,
                    ShiftId      = 1,
                    DateAssigned = DateTime.Now.AddDays(1)
                }
            };
            context.PersonnelShifts.AddRange(personnelShifts);
            #endregion

            context.SaveChanges();

            #region Personnel Shift Assignments
            var shiftAssignDates = new List <PersonnelShiftAssignment>
            {
                new PersonnelShiftAssignment
                {
                    PersonnelShiftId = 1,
                    Date             = DateTime.Now.Date
                },
                new PersonnelShiftAssignment
                {
                    PersonnelShiftId = 2,
                    Date             = DateTime.Now.Date.AddDays(1)
                }
            };
            context.PersonnelShiftAssignments.AddRange(shiftAssignDates);
            #endregion

            #region Personnel Shift Replacements
            var shiftReplacements = new List <PersonnelShiftReplacement>
            {
                new PersonnelShiftReplacement
                {
                    PersonnelId           = 1,
                    ReplacedPersonnelId   = 2,
                    WorkingHourId         = 1,
                    ReplacedWorkingHourId = 1,
                    RequestedDate         = DateTime.Now.AddDays(-2),
                    ActionDate            = DateTime.Now.AddDays(-1),
                    ReplacementDate       = DateTime.Now.AddDays(-1),
                    RequestAction         = RequestAction.Accept
                },
                new PersonnelShiftReplacement
                {
                    PersonnelId           = 1,
                    ReplacedPersonnelId   = 2,
                    WorkingHourId         = 2,
                    ReplacedWorkingHourId = 2,
                    RequestedDate         = DateTime.Now.AddDays(-1),
                    ActionDate            = DateTime.Now,
                    ReplacementDate       = DateTime.Now,
                    RequestAction         = RequestAction.Accept
                },
            };
            context.PersonnelShiftReplacements.AddRange(shiftReplacements);
            #endregion

            #region Approval Procs
            var approvalProc1 = new ApprovalProc
            {
                ParentId         = null,
                Title            = "Approval Group 1",
                FirstPriorityId  = 1,
                SecondPriorityId = 2,
                ThirdPriorityId  = null,
                ActiveState      = ActiveState.Active
            };
            var approvalProc2 = new ApprovalProc
            {
                ParentId         = 1,
                Title            = "Approval Group 2",
                FirstPriorityId  = 2,
                SecondPriorityId = null,
                ThirdPriorityId  = null,
                ActiveState      = ActiveState.Active
            };
            context.ApprovalProcs.Add(approvalProc1);
            context.SaveChanges();
            context.ApprovalProcs.Add(approvalProc2);

            #endregion

            base.Seed(context);
        }