public void Remove(DisPeriodNo period)
 {
     if (Context.Entry(period).State == EntityState.Detached)
     {
         context.DisPeriodNo.Attach(period);
     }
     context.DisPeriodNo.Remove(period);
 }
        private void GetPeriodNO(DisplinPeriodViewModel model, DisplinPeriod record)
        {
            var      period     = _hrUnitOfWork.Repository <DisPeriodNo>().Where(s => s.PeriodId == record.Id).Select(a => a.PeriodNo).LastOrDefault();
            int      day        = model.PeriodSDate.Day;
            int      modelYear  = model.PeriodSDate.Year;
            DateTime startTime  = model.PeriodSDate;
            DateTime endTime    = model.PeriodSDate;
            DateTime customName = model.PeriodSDate;
            //int year1 = 0;
            int year = 0;

            if (model.Frequency == 1)
            {
                year = 360;
            }
            else if (model.Frequency == 2)
            {
                year = 52;
            }
            else if (model.Frequency == 3)
            {
                year = 12;
            }
            else
            {
                year = 1;
            }
            int?Iteration = (model.TotalYear * year) / model.Times;

            for (int i = 0; i < Iteration; i++)
            {
                if (model.Frequency == 3)
                {
                    startTime = model.PeriodSDate.AddMonths(model.Times * i);
                    endTime   = model.PeriodSDate.AddMonths(model.Times * (i + 1)).AddDays(-1);
                    //int month = model.PeriodSDate.Month + i * model.Times;
                    //int Year = modelYear;
                    //if (month > 12)
                    //{

                    //    Year = modelYear + Convert.ToInt32(month/12);
                    //    year1 = Convert.ToInt32(month / 12);
                    //    month = month - (year1 * 12);
                    //}
                    //startTime = new DateTime(Year, month, day);
                    //endTime = startTime.AddMonths(model.Times).AddDays(-1);
                }
                else if (model.Frequency == 4)
                {
                    startTime = model.PeriodSDate.AddYears(model.Times * i);
                    endTime   = model.PeriodSDate.AddYears(model.Times * (i + 1)).AddDays(-1);
                }
                else if (model.Frequency == 1)
                {
                    startTime = model.PeriodSDate.AddDays(model.Times * i);
                    endTime   = model.PeriodSDate.AddDays(model.Times * (i + 1)).AddDays(-1);
                }
                else
                {
                    int Calcweak = model.Times * 7;
                    startTime = model.PeriodSDate.AddDays(Calcweak * i);
                    endTime   = model.PeriodSDate.AddDays(Calcweak * (i + 1)).AddDays(-1);
                }

                DisPeriodNo periodNo = new DisPeriodNo()
                {
                    PeriodNo    = ++period,
                    CreatedUser = UserName,
                    Posted      = false,
                    PostDate    = DateTime.Now,
                    CreatedTime = DateTime.Now,
                    Name        = startTime.ToString("MM/yyyy"),
                    PeriodEDate = endTime,
                    PeriodSDate = startTime,
                    PeriodId    = record.Id
                };

                _hrUnitOfWork.DisciplineRepository.Add(periodNo);
            }
        }
 public void Attach(DisPeriodNo period)
 {
     context.DisPeriodNo.Attach(period);
 }
 public DbEntityEntry <DisPeriodNo> Entry(DisPeriodNo period)
 {
     return(Context.Entry(period));
 }
 public void Add(DisPeriodNo period)
 {
     context.DisPeriodNo.Add(period);
 }