public IHttpActionResult GetItems(int modelId, string serialNum, string batchNum, string macAddress, int?page, int?count) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { int totalCount = 0; var items = db.GetItems(modelId, serialNum, batchNum, macAddress, page, count).OrderBy(x => x.SerialNumber).ToList(); if (items.Count > 0) { totalCount = (int)items.FirstOrDefault().TotalCount; } return(Content(HttpStatusCode.OK, new { items, 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 agin later")); } }