Home Pass a single event without ending date in full calendar
Reply: 0

Pass a single event without ending date in full calendar

user4617
1#
user4617 Published in April 25, 2018, 12:51 am

I am trying to render a event in the calendar with both start and ending date the same, i.e. I only intend to show a single line in the Day view of the calendar.

I tried 2 approaches;

First approach includes (an ajax call to a method that fetches a pair of innDateTime and outDateTime, then stores those two to a list which is sent to the calendar for rendering) This works however the behaviour is very untidy as it creates a block of inappropriate timeslot:

Index.cshtml:

//missing entry///

                      $.ajax({
                          url: baseUrl +  'Stats/missingEntryDayJsonReturn?EnrollNumber=' + event.id + '&StartDate=' + event.start.format('YYYY-MM-DD'),
                          contenttype: 'application/json',
                          data: '',//JSON.stringify(params)
                          type: 'post'
                      }).done(function (data) {
                          console.log('bogus entry picked! ', data);

                          var calRes = $("#calendar").fullCalendar('addEventSource', data);
                      });

Controller:

 public ActionResult missingEntryDayJsonReturn(int EnrollNumber, string StartDate)
        {
            Calculations calc = new Calculations();
            List<Pair> logs = new List<Pair>();
            DateTime dt = DateTime.Parse(StartDate);
            logs = calc.getSingleDevicePairs(EnrollNumber, dt, dt, 1);
            var eventList = from e in logs
                            select new
                            {
                                id = e.id,
                                title = "Time Spent : " + (e.OutDateTime - e.InnDateTime),
                                start = ((DateTime)e.InnDateTime).ToString("s"),
                                end = ((DateTime)e.OutDateTime).ToString("s"),
                                allDay = false
                            };
            var rows = eventList.ToArray();
            return Json(rows, JsonRequestBehavior.AllowGet);
}

  public List<Pair> getSingleDevicePairs(int EnrollNumber, DateTime StartDate, DateTime EndDate, int? missingEntry)
{
if(missingEntry == 1)
{
   List<Pair> pairList = new List<Pair>();
 Pair missingPair = new Pair();
                var missingLog = db.AttendanceLogs.Where(x => x.RegisterationId == EnrollNumber && x.Date >= StartDate &&
              x.Date <= EndDate && x.isIgnore != true && x.CheckType == "In").OrderByDescending(x => x.DateTime).FirstOrDefault();
                missingPair.InnDateTime = missingLog.DateTime;

missingPair.OutDateTime= missingLog.DateTime;
pairList.Add(missingPair);
                return pairList;  
}
}

OUTPUT:

This understood as I am passing a list, I'm now trying to pass only the start and single entry like:

   public ActionResult missingEntryDayJsonReturn(int EnrollNumber, string StartDate)
        {
 Calculations calc = new Calculations();
            Pair missingLog = new Pair();
            DateTime dt = DateTime.Parse(StartDate);
            missingLog = calc.getMissingEntry(EnrollNumber, dt, dt);

            var eventList = from e in missingLog
                            select new
                            {
                                id = e.id,
                                title = "Invalid Punch: " + (e.OutDateTime - e.InnDateTime),
                                start = ((DateTime)e.InnDateTime).ToString("s"),
                                end = ((DateTime)e.OutDateTime).ToString("s"),
                                allDay = false
                            };
            var rows = eventList.ToArray();
            return Json(rows, JsonRequestBehavior.AllowGet);

}

^^ERROR: Could not find an implementation of the query pattern for source type 'Pair'. 'Select' not found.

 public Pair getMissingEntry(int EnrollNumber, DateTime StartDate, DateTime EndDate)
        {
                Pair missingPair = new Pair();
                var missingLog = db.AttendanceLogs.Where(x => x.RegisterationId == EnrollNumber && x.Date >= StartDate &&
              x.Date <= EndDate && x.isIgnore != true && x.CheckType == "In").OrderByDescending(x => x.DateTime).FirstOrDefault();
                missingPair.InnDateTime = missingLog.DateTime;
                return missingPair;          
        }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.297987 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO