public IHttpActionResult GetLeadsList(DateTime?fromDate, DateTime?toDate, string opportunity, string client, string assignTo, string status, int?orgId, int?page, int?count) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { int?totalCount = 0; var opportunities = db.GetLeads(fromDate, toDate, opportunity, client, assignTo, status, orgId, page, count).OrderByDescending(x => x.CreatedDate).ToList(); if (opportunities.Count() > 0) { totalCount = (int)opportunities.FirstOrDefault().TotalCount; } return(Content(HttpStatusCode.OK, new { opportunities, totalCount })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }