public ActionResult Orders(DateTime startDate, DateTime endDate, string databaseName, string customerId, string companyId) { APIAuth auth = new APIAuth(Request, Response); AuthInfo authInfo = auth.CheckLogin(); if (authInfo.IsAuthenticated) { Customer localCust = new Customer(); localCust.DatabaseName = databaseName; localCust.CustomerId = customerId; localCust.CompanyId = companyId; //Check if this user has access to this customer var userCustomers = db.GetUserCustomersSync(authInfo.User.Id); //Customer selectedCompany = userCustomers.Where(x => x.CustomerKey == localCust.CustomerKey).First(); //return Json(new { foo = "ok", baz = "alee" }); //if (selectedCompany != null) if (userCustomers.Count(x => x.CustomerKey == localCust.CustomerKey) > 0) { IEnumerable <RentalOrder> orders; Customer activeCust = db.GetCustomer(localCust.DatabaseName, localCust.CompanyId, localCust.CustomerId); if (activeCust.showChildBROrders) { var validCustomers = new OverviewDAL().GetCustomersRegisteredSync().Where(x => x.DatabaseName == activeCust.DatabaseName && x.CompanyId == activeCust.CompanyId); orders = db.GetRentalOrdersChildBRSync(activeCust, startDate, endDate); orders = orders.Join(validCustomers, x => x.CustAccount, y => y.CustomerId, (ord, cust) => ord); } else { orders = db.GetRentalOrdersSync(localCust, startDate, endDate); } //need to manually add trackunit data RentalsDAL dbRental = new RentalsDAL(); IEnumerable <TrackUnitData> units = dbRental.GetTrackUnitDataSync(); using (var orderEnum = orders.GetEnumerator()) { while (orderEnum.MoveNext()) { RentalOrder order = orderEnum.Current; var unit = units.Where(x => x.ReferenceNumber == order.ObjectId).FirstOrDefault(); if (unit != null) { order.IsMachineLocalized = true; order.Latitude = unit.Latitude; order.Longitude = unit.Longitude; TimeSpan diffTime = DateTime.Now.Subtract(unit.GpsFixTime); if (diffTime.TotalMinutes > 240) { order.markerColor = "yellow"; } else if (unit.Speed > 15) { order.markerColor = "green"; } else if (unit.Input1.Value == true) { order.markerColor = "blue"; } else { order.markerColor = "red"; } } else { order.IsMachineLocalized = false; order.Latitude = 0.0; order.Longitude = 0.0; order.markerColor = ""; } } } //END trackunit //new CustomJsonResult( //return Content(new JavaScriptSerializer().Serialize(orders.ToList()), "application/json"); return(new CustomJsonResult { Data = orders.ToList() }); } else { return(Json(new { error = "No access" }, JsonRequestBehavior.AllowGet)); } } else { return(auth.Forbidden()); } }