private BiometricData GetBiometryData(PersonnelMachine machineperson)
        {
            var bio = new BiometricData();

            bio.Date             = DateTime.Now;
            bio.PersonnelMachine = machineperson;
            bio.BiometricDataTimes.Add(new BiometricDataTime
            {
                TimeIn  = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 30, 20),
                TimeOut = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 9, 30, 10),
            });


            bio.BiometricDataTimes.Add(new BiometricDataTime
            {
                TimeIn  = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 11, 00, 20),
                TimeOut = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 12, 0, 0),
            });


            bio.BiometricDataTimes.Add(new BiometricDataTime
            {
                TimeIn  = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 16, 15, 20),
                TimeOut = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 17, 45, 1),
            });

            bio.BiometricDataTimes.Add(new BiometricDataTime
            {
                TimeIn  = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 19, 59, 58),
                TimeOut = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.AddDays(1).Day, 1, 0, 0),
            });

            return(bio);
        }
        public void init()
        {
            using (var db = new EngineContext())
            {
                var workgroup = new WorkGroup
                {
                    Name = "شیفت کار عادی",
                };
                db.WorkGroups.Add(workgroup);

                personnel = new Personnel
                {
                    Name     = "mohammad",
                    LastName = "Jafaryan",
                };
                db.Personnels.Add(personnel);

                var machine = new Machine
                {
                    Name = "Samsung"
                };
                db.Machines.Add(machine);


                var machineperson = new PersonnelMachine
                {
                    Machine   = machine,
                    Personnel = personnel
                };
                db.PersonnelMachines.Add(machineperson);

                var obligaterange = new ObligatedRange
                {
                    Name   = "شیف کار",
                    OffDay = DayOfWeek.Friday,
                    ObligatedRangeWeeks = GetWeek()
                };
                db.ObligatedRanges.Add(obligaterange);

                SetTimesShift(obligaterange.ObligatedRangeWeeks.ToList());

                var bio = GetBiometryData(machineperson);
                db.BiometricDatas.Add(bio);


                var workgroupRange = new WorkGroupObligatedRange
                {
                    ObligatedRange = obligaterange,
                    WorkGroup      = workgroup
                };


                db.WorkGroupObligatedRanges.Add(workgroupRange);


                db.SaveChanges();
            }
        }
        private List <BiometricData> GetBiometryDataNights
            (PersonnelMachine machineperson, DateTime day)
        {
            List <BiometricData> dates = new List <BiometricData>();


            //sat
            dates.Add(new BiometricData
            {
                Date               = day,
                PersonnelMachine   = machineperson,
                BiometricDataTimes = new List <BiometricDataTime>
                {
                    new BiometricDataTime
                    {
                        TimeIn  = new DateTime(day.Year, day.Month, day.Day, 20, 30, 20),
                        TimeOut = new DateTime(day.Year, day.Month, day.AddDays(1).Day, 6, 0, 10),
                    }
                }
            });
// sun
            day = day.AddDays(1);
            dates.Add(new BiometricData
            {
                Date               = day,
                PersonnelMachine   = machineperson,
                BiometricDataTimes = new List <BiometricDataTime>
                {
                    new BiometricDataTime
                    {
                        TimeIn  = new DateTime(day.Year, day.Month, day.Day, 19, 45, 20),
                        TimeOut = new DateTime(day.Year, day.Month, day.AddDays(1).Day, 6, 0, 15),
                    }
                }
            });

//mon
            day = day.AddDays(1);
            dates.Add(new BiometricData
            {
                Date               = day,
                PersonnelMachine   = machineperson,
                BiometricDataTimes = new List <BiometricDataTime>
                {
                    new BiometricDataTime
                    {
                        TimeIn  = new DateTime(day.Year, day.Month, day.Day, 20, 17, 20),
                        TimeOut = new DateTime(day.Year, day.Month, day.AddDays(1).Day, 6, 0, 1),
                    }
                }
            });

            /*
             * // tue
             * day= day.AddDays(1);
             * bio.BiometricDataTimes.Add(new BiometricDataTime
             * {
             *  TimeIn = new DateTime(day.Year, day.Month, day.Day, 21, 59, 48),
             *  TimeOut = new DateTime(day.Year, day.Month,day.AddDays(1).Day, 5, 59, 0),
             * });
             */

            // wed
            day = day.AddDays(1);
            dates.Add(new BiometricData
            {
                Date               = day,
                PersonnelMachine   = machineperson,
                BiometricDataTimes = new List <BiometricDataTime>
                {
                    new BiometricDataTime
                    {
                        TimeIn  = new DateTime(day.Year, day.Month, day.Day, 22, 0, 58),
                        TimeOut = new DateTime(day.Year, day.Month, day.AddDays(1).Day, 6, 0, 0),
                    }
                }
            });
            // th
            day = day.AddDays(1);
            dates.Add(new BiometricData
            {
                Date               = day,
                PersonnelMachine   = machineperson,
                BiometricDataTimes = new List <BiometricDataTime>
                {
                    new BiometricDataTime
                    {
                        TimeIn  = new DateTime(day.Year, day.Month, day.Day, 18, 30, 58),
                        TimeOut = new DateTime(day.Year, day.Month, day.AddDays(1).Day, 6, 10, 0),
                    }
                }
            });

            //frid

            day = day.AddDays(1);
            dates.Add(new BiometricData
            {
                Date               = day,
                PersonnelMachine   = machineperson,
                BiometricDataTimes = new List <BiometricDataTime>
                {
                    new BiometricDataTime
                    {
                        TimeIn  = new DateTime(day.Year, day.Month, day.Day, 18, 0, 58),
                        TimeOut = new DateTime(day.Year, day.Month, day.AddDays(1).Day, 6, 0, 0),
                    }
                }
            });

            return(dates);
        }
        private List <BiometricData> GetBiometryDataDays(PersonnelMachine machineperson, out DateTime dateTime)
        {
            List <BiometricData> dates = new List <BiometricData>();
            var day = DateTime.Now;

            dates.Add(new BiometricData
            {
                Date               = day,
                PersonnelMachine   = machineperson,
                BiometricDataTimes = new List <BiometricDataTime>
                {
                    new BiometricDataTime
                    {
                        TimeIn  = new DateTime(day.Year, day.Month, day.Day, 8, 30, 20),
                        TimeOut = new DateTime(day.Year, day.Month, day.Day, 18, 30, 10),
                    }
                }
            });

// sun
            day = day.AddDays(1);
            dates.Add(new BiometricData
            {
                Date               = day,
                PersonnelMachine   = machineperson,
                BiometricDataTimes = new List <BiometricDataTime>
                {
                    new BiometricDataTime
                    {
                        TimeIn  = new DateTime(day.Year, day.Month, day.Day, 8, 0, 20),
                        TimeOut = new DateTime(day.Year, day.Month, day.Day, 17, 59, 15),
                    }
                }
            });

//mon
            day = day.AddDays(1);

            dates.Add(new BiometricData
            {
                Date               = day,
                PersonnelMachine   = machineperson,
                BiometricDataTimes = new List <BiometricDataTime>
                {
                    new BiometricDataTime
                    {
                        TimeIn  = new DateTime(day.Year, day.Month, day.Day, 8, 17, 20),
                        TimeOut = new DateTime(day.Year, day.Month, day.Day, 18, 45, 1),
                    }
                }
            });

            // tue
            day = day.AddDays(1);
            dates.Add(new BiometricData
            {
                Date               = day,
                PersonnelMachine   = machineperson,
                BiometricDataTimes = new List <BiometricDataTime>
                {
                    new BiometricDataTime
                    {
                        TimeIn  = new DateTime(day.Year, day.Month, day.Day, 7, 59, 58),
                        TimeOut = new DateTime(day.Year, day.Month, day.Day, 17, 0, 0),
                    }
                }
            });

            // wed
            day = day.AddDays(1);

            dates.Add(new BiometricData
            {
                Date               = day,
                PersonnelMachine   = machineperson,
                BiometricDataTimes = new List <BiometricDataTime>
                {
                    new BiometricDataTime
                    {
                        TimeIn  = new DateTime(day.Year, day.Month, day.Day, 7, 59, 58),
                        TimeOut = new DateTime(day.Year, day.Month, day.Day, 17, 0, 0),
                    }
                }
            });
            // th
            day = day.AddDays(1);
            dates.Add(new BiometricData
            {
                Date               = day,
                PersonnelMachine   = machineperson,
                BiometricDataTimes = new List <BiometricDataTime>
                {
                    new BiometricDataTime
                    {
                        TimeIn  = new DateTime(day.Year, day.Month, day.Day, 7, 30, 58),
                        TimeOut = new DateTime(day.Year, day.Month, day.Day, 18, 10, 0),
                    }
                }
            });

            //frid

            day = day.AddDays(1);

            dates.Add(new BiometricData
            {
                Date               = day,
                PersonnelMachine   = machineperson,
                BiometricDataTimes = new List <BiometricDataTime>
                {
                    new BiometricDataTime
                    {
                        TimeIn  = new DateTime(day.Year, day.Month, day.Day, 9, 0, 58),
                        TimeOut = new DateTime(day.Year, day.Month, day.Day, 18, 0, 0),
                    }
                }
            });

            dateTime = day;

            return(dates);
        }
        public void init()
        {
            using (var db = new EngineContext())
            {
                var workgroup = new WorkGroup
                {
                    Name = "شیفت چهار هفته ای",
                };
                db.WorkGroups.Add(workgroup);

                personnel = new Personnel
                {
                    Name     = "بهزاد",
                    LastName = "خوشاوند",
                };
                db.Personnels.Add(personnel);

                var machine = new Machine
                {
                    Name = "Samsung"
                };
                db.Machines.Add(machine);


                var machineperson = new PersonnelMachine
                {
                    Machine   = machine,
                    Personnel = personnel
                };
                db.PersonnelMachines.Add(machineperson);


                var w1 = GetWeek(1); //روزکار
                var w2 = GetWeek(2); //شب کار

                SetDayShifts(w1);
                SetNightShifts(w2);

                var obligatedRangeWeeks = w1;
                obligatedRangeWeeks.AddRange(w2);
                var obligaterange = new ObligatedRange
                {
                    Name   = "شیف کار",
                    OffDay = DayOfWeek.Friday,
                    ObligatedRangeWeeks = obligatedRangeWeeks
                };
                db.ObligatedRanges.Add(obligaterange);

                // SetTimesShift(obligaterange.ObligatedRangeWeeks.ToList());

                DateTime date;
                var      bio    = GetBiometryDataDays(machineperson, out date);
                var      nights = GetBiometryDataNights(machineperson, date);

                db.BiometricDatas.AddRange(bio);
                db.BiometricDatas.AddRange(nights);


                var workgroupRange = new WorkGroupObligatedRange
                {
                    ObligatedRange = obligaterange,
                    WorkGroup      = workgroup,
                    DateTime       = DateTime.Now
                };


                this.workgroupRange = workgroupRange;

                db.WorkGroupObligatedRanges.Add(workgroupRange);


                db.SaveChanges();
            }
        }