public ActionResult PartialDay(int?timehelperId, int?ProgramTeachingHoursPerDay, int?month, int?year, int?day, int?programid)
        {
            ViewBag.ProgramTeachingHoursPerDay = (int)ProgramTeachingHoursPerDay;
            if (timehelperId != null && timehelperId != 0)
            {
                var singleDayReference = db.TimeOfCourse.Find(timehelperId);
                var allCoursesDetails  = db.CourseWithTimeAllocations.Where(x => x.TimeAllocationHelperId == singleDayReference.Id).ToList();
                ViewBag.TimeId = timehelperId.Value;

                return(View(allCoursesDetails));
            }
            DateTime             timeOfDate           = new DateTime(year.Value, month.Value, day.Value);
            TimeAllocationHelper timeAllocationHelper = new TimeAllocationHelper();

            timeAllocationHelper.Date      = timeOfDate;
            timeAllocationHelper.ProgramId = programid.Value;

            timeAllocationHelper.RemainingTime = db.Programs.Find(programid).TotalTeachingHoursOfDay;
            db.TimeOfCourse.Add(timeAllocationHelper);
            db.SaveChanges();
            var ins = db.TimeOfCourse.Where(x => x.Date == timeOfDate && x.ProgramId == programid).ToList().FirstOrDefault();

            ViewBag.TimeId = ins.Id;
            return(View(new List <CourseWithTimeAllocation>()));
        }
        public ActionResult MonthView(DateTime?startdate, DateTime?enddate, int?monthNum, int?programId)
        {
            DateTime month = startdate.Value;

            if (monthNum != null && monthNum != 0)
            {
                month = month.AddMonths((int)monthNum);
                ViewBag.StartingDate = 0;
                ViewBag.EndingDate   = 100;
            }
            else if (month != null && monthNum == 0)
            {
                ViewBag.StartingDate = (month.Day - 1);
            }
            List <DayOfWeek> dayOfWeeks = new List <DayOfWeek>()
            {
                DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday
            };
            DateTime st             = new DateTime(month.Year, month.Month, 1);
            int      startingNumber = 0;

            for (int d = 0; d < dayOfWeeks.Count(); d++)
            {
                if (dayOfWeeks[d] == st.DayOfWeek)
                {
                    startingNumber = d;
                }
            }

            ViewBag.StartingDay = startingNumber;

            if (month.Month == enddate.Value.Month && month.Year == enddate.Value.Year)
            {
                //last month
                ViewBag.EndingDate = month.Day + 1;
            }

            if (month.Month == 2)
            {
                if (month.Year % 4 == 0 && month.Year % 100 != 0)
                {
                    ViewBag.TotalDays = 29;
                }
                else
                {
                    ViewBag.TotalDays = 28;
                }
            }
            else if (month.Month < 8 && month.Month % 2 == 0)
            {
                ViewBag.TotalDays = 30;
                // months feb
            }
            else if (month.Month < 8 && month.Month % 2 == 1)
            {
                ViewBag.TotalDays = 31;
            }
            else if (month.Month >= 8 && month.Month % 2 == 0)
            {
                ViewBag.TotalDays = 31;
            }
            else if (month.Month >= 8 && month.Month % 2 == 1)
            {
                ViewBag.TotalDays = 30;
            }
            else
            {
                ViewBag.TotalDays = 0;
            }

            ViewBag.Month     = month.ToString("MMMM");
            ViewBag.Year      = month.Year.ToString();
            ViewBag.Date      = startdate.Value;
            ViewBag.DataMonth = month.Month;
            ViewBag.DataYear  = month.Year;
            List <TimeAllocationHelper> allAssignedTimeTable = db.TimeOfCourse.Where(x => x.ProgramId == programId && x.Date.Month == month.Month && x.Date.Year == month.Year).ToList();
            List <DateTime>             haveDates            = allAssignedTimeTable.Select(x => x.Date).ToList();
            DateTime tempStartDate = new DateTime(month.Year, month.Month, 1);

            while (tempStartDate.Month == month.Month)
            {
                if (haveDates.Contains(tempStartDate) == false)
                {
                    TimeAllocationHelper tempAllocator = new TimeAllocationHelper()
                    {
                        Id = 0, Date = tempStartDate, Day = 'N', ProgramId = programId.Value
                    };
                    allAssignedTimeTable.Add(tempAllocator);
                }

                tempStartDate = tempStartDate.AddDays(1);
            }
            var TempProgram = db.Programs.Find(programId);
            List <HelperOfDateHoliday> allHolidaysForThisMonthDates = db.Calendars.Where(x => x.ProgramId == programId && x.Date.Month == month.Month && x.Date.Year == month.Year).ToList().Select(x => new HelperOfDateHoliday()
            {
                Date = x.Date, IsHoliday = x.IsHoliday
            }).ToList();
            EditCalendarHelper editCalendarHelper = new EditCalendarHelper()
            {
                DateHelper = allAssignedTimeTable.OrderBy(x => x.Date).ToList(), startDate = startdate.Value, endDate = enddate.Value, ProgramTeachingHoursPerDay = TempProgram.TotalTeachingHoursOfDay, month = month.Month, year = month.Year, ProgramId = programId.Value
            };
            List <bool> flagsForHolidays = new List <bool>();

            foreach (var op in editCalendarHelper.DateHelper)
            {
                var dd = allHolidaysForThisMonthDates.Find(x => x.Date == op.Date);
                if (dd == null)
                {
                    flagsForHolidays.Add(true);
                }
                else
                {
                    if (dd.IsHoliday == true)
                    {
                        flagsForHolidays.Add(true);
                    }
                    else
                    {
                        flagsForHolidays.Add(false);
                    }
                }
            }
            editCalendarHelper.holidays = flagsForHolidays;

            return(View(editCalendarHelper));
        }