public JsonResult RecentOrders() { try { var recentOrders = new List <OrderHeader>(); var userResponse = this.AccountManager.GetUser(Context.User.Name); var result = new OrdersBaseJsonResult(userResponse.ServiceProviderResult); if (userResponse.ServiceProviderResult.Success && userResponse.Result != null) { var commerceUser = userResponse.Result; var response = this.OrderManager.GetOrders(commerceUser.ExternalId, Context.Site.Name); result.SetErrors(response.ServiceProviderResult); if (response.ServiceProviderResult.Success && response.Result != null) { var orders = response.Result.ToList(); recentOrders = orders.Where(order => (order as CommerceOrderHeader).LastModified > DateTime.Today.AddDays(-30)).Take(5).ToList(); } } result.Initialize(recentOrders); return(Json(result, JsonRequestBehavior.AllowGet)); } catch (Exception e) { CommerceLog.Current.Error("RecentOrders", this, e); return(Json(new BaseJsonResult("RecentOrders", e), JsonRequestBehavior.AllowGet)); } }
public OrdersBaseJsonResult GetRecentOrders(string userName) { var recentOrders = new List <OrderHeader>(); var userResponse = this.AccountManager.GetUser(userName); var result = new OrdersBaseJsonResult(userResponse.ServiceProviderResult); if (userResponse.ServiceProviderResult.Success && userResponse.Result != null) { var commerceUser = userResponse.Result; var response = this.OrderManager.GetOrders(commerceUser.ExternalId, Context.Site.Name); result.SetErrors(response.ServiceProviderResult); if (response.ServiceProviderResult.Success && response.Result != null) { var orders = response.Result.ToList(); recentOrders = orders.Where(order => (order as CommerceOrderHeader).LastModified > DateTime.Today.AddDays(ReturnLastModifiedOrdersDaysOld)) .Take(ReturnLastModifiedOrdersNum).ToList(); } } result.Initialize(recentOrders); return(result); }