0

i am using mvc web api as background api of ionic project(using angularjs) and want to use session for passing data to dictionary,in order that i can get limited data from total data and display them in first page,then next data as well as scrolling, please help me

[HttpGet]
[Route("user/takenCourseDetails")]
[ResponseType(typeof(TeachMatEventsModelView))]
public IHttpActionResult takenCourseDetails(int masterCourseId, int secId, int page, int PageSize, int IsPaging)
        {
            if (IsPaging == 0)
            {
                if (page == 0)
                {
                    LoadAllEventToSession(masterCourseId, secId);

                    var eventList = GetProductsForPage(page);
                    return Ok(eventList);
                }
            }
            return Ok();
        }

public void LoadAllEventToSession(int masterCourseId, int secId)
        {

            if (db.View_TeachMatEventList.Where(m => m.MasterCourseId == masterCourseId && m.SectionId == secId).Any())
            {
                var allEventList = db.View_TeachMatEventList.Where(m => m.MasterCourseId == masterCourseId && m.SectionId == secId
                   && m.HasParent==false && m.Status == 1).OrderBy(m => m.EventNumber).ToList();

                int cmnIndex = 1;

                var session = HttpContext.Current.Session;
                session["event"] = allEventList.ToDictionary(m => cmnIndex++, m => m);
                session["totalEvent"] = allEventList.Count();

            }

        }
 public Dictionary<int, TeachMatEventsModelView> GetProductsForPage(int pageNum)
        {
            var session = HttpContext.Current.Session;
            Dictionary<int, TeachMatEventsModelView> eventList= (session["event"] as Dictionary<int, TeachMatEventsModelView>);
            int from = (pageNum * ShowEventPerPage);
            int to = from + ShowEventPerPage;//ShowEventPerPage=5;
            return eventList.Where(x => x.Key > from && x.Key <= to).OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
        }

Error: error

austBD.60
  • 1
  • 1
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Federico Dipuma May 19 '16 at 12:24
  • Already solved by another way. Because session variable is not working here properly. Thank you. – austBD.60 May 25 '16 at 05:46

0 Answers0