Esempio n. 1
0
        private List<CalendarModel> getMonths(int start, int end)
        {
            List<CalendarModel> examsList = new List<CalendarModel>();
            List<String> distictYears = new List<String>();
            foreach (var item in context.EXAMDATESBY(start, end))
            {
                cm = new CalendarModel();
                DateTime dt = (DateTime)item.STARTDATE;
                DateTime startDate = (DateTime)item.STARTDATE;
                DateTime endDate = (DateTime)item.ENDDATE;
                cm.dt = dt;
                cm.id = item.ID;
                cm.page = start;
                cm.lastMonth = end;
                cm.startDate = startDate;
                cm.endDate = endDate;
                cm.exam = item.EXAMNAME.Trim();
                cm.year = cm.getYear();
                cm.hour = cm.getHour();
                cm.month = cm.getMonth();
                cm.minute = cm.getMinute();

                if (distictYears.Contains(cm.getMonth()) == false
                    | distictYears.Count == 0)
                {
                    distictYears.Add(cm.getMonth());
                    examsList.Add(cm);
                }
            }
            return examsList;
        }
Esempio n. 2
0
        public ActionResult Exams(int? id)
        {
            List<CalendarModel> availableExamsList = new List<CalendarModel>();
            if (id != null)
            {
                //get the datetime from database for future casting
                var querry = from data in context.EXAMs
                             where data.ID == id
                             select data;
                var exam = querry.First();
                //create a date and time object to get the casting done
                CalendarModel cm;
                cm = new CalendarModel();
                cm.setDateTime((DateTime)exam.STARTDATE);
                DateTime nowDate = DateTime.Now;
                cm.startDate = nowDate;
                //consult for exams with date and time object
                var exams = from data in context.EXAMs
                             where data.STARTDATE.Value.Month.ToString()
                             == cm.getMonth()
                             & data.STARTDATE.Value.Year.ToString()
                             == cm.getYear()
                             & data.STARTDATE
                             >= cm.startDate
                             orderby data.EXAMNAME ascending
                             select data;
                //add to date and time object all the data returned from db

                foreach (var item in exams)
                {
                    cm = new CalendarModel();
                    cm.id = item.ID;
                    cm.hour = item.STARTDATE.Value.Hour.ToString();
                    cm.minute = item.STARTDATE.Value.Minute.ToString();
                    cm.second = item.STARTDATE.Value.Second.ToString();
                    cm.startDate =(DateTime) item.STARTDATE;
                    cm.endDate = (DateTime)item.ENDDATE;
                    cm.exam = item.EXAMNAME;
                    availableExamsList.Add(cm);
                }
            }

            return View(availableExamsList);
        }