public IHttpActionResult GetStockRequest(int stockReqId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var user = User.Identity.GetUserId(); var emp = db.Employees.Where(x => x.AspNetUserId == user).FirstOrDefault(); /* Stored procedure to get the items requested */ var stockRequest = db.GetStockRequest(stockReqId).ToList(); var stockRequestData = stockRequest.GroupBy(x => x.Id).Select(x => x.First()).Select(x => new { x.Id, ClientId = x.Client, ClientName = x.ShortName, x.RequestDate, x.ExpectedStockDate, x.Notes, x.TaskId, x.Employee, ProjectId = x.opportunityId, ProjectName = x.OpportunityName, x.Status, x.StockReqMappingId, x.Location_Id, x.ProjectLocation, Items = stockRequest.GroupBy(y => y.ModelId).Select(y => y.First()).Select(y => new { y.ModelId, ItemName = y.Model, Quantity = y.Quanitity, y.Description, y.StockReqMappingId, y.NoOfItemsAvailable }).ToList() }).FirstOrDefault(); //var stockRequestItems = db.GetStockRequest(stockReqId).GroupBy(x => x.ModelId).Select(x => x.First()).Select(x => new //{ // ModelId = x.ModelId, // ItemName = x.Model, // Quantity = x.Quanitity, // Description = x.Description, // StockReqMappingId = x.StockReqMappingId, // x.NoOfItemsAvailable //}).ToList(); return(Content(HttpStatusCode.OK, new { stockRequestData })); } } 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")); } }