public Subscription[] GetByIds(string[] subscriptionIds, string responseGroup = null) { var retVal = new List <Subscription>(); var subscriptionResponseGroup = EnumUtility.SafeParse(responseGroup, SubscriptionResponseGroup.Full); using (var repository = _subscriptionRepositoryFactory()) { repository.DisableChangesTracking(); var subscriptionEntities = repository.GetSubscriptionsByIds(subscriptionIds, responseGroup); foreach (var subscriptionEntity in subscriptionEntities) { var subscription = AbstractTypeFactory <Subscription> .TryCreateInstance(); if (subscription != null) { subscription = subscriptionEntity.ToModel(subscription) as Subscription; if (subscriptionResponseGroup.HasFlag(SubscriptionResponseGroup.WithChangeLog)) { //Load change log by separate request _changeLogService.LoadChangeLogs(subscription); } retVal.Add(subscription); } } } CustomerOrder[] orderPrototypes = null; CustomerOrder[] subscriptionOrders = null; if (subscriptionResponseGroup.HasFlag(SubscriptionResponseGroup.WithOrderPrototype)) { orderPrototypes = _customerOrderService.GetByIds(retVal.Select(x => x.CustomerOrderPrototypeId).ToArray()); } if (subscriptionResponseGroup.HasFlag(SubscriptionResponseGroup.WithRelatedOrders)) { //Loads customer order prototypes and related orders for each subscription via order service var criteria = new CustomerOrderSearchCriteria { SubscriptionIds = subscriptionIds }; subscriptionOrders = _customerOrderSearchService.SearchCustomerOrders(criteria).Results.ToArray(); } foreach (var subscription in retVal) { if (!orderPrototypes.IsNullOrEmpty()) { subscription.CustomerOrderPrototype = orderPrototypes.FirstOrDefault(x => x.Id == subscription.CustomerOrderPrototypeId); } if (!subscriptionOrders.IsNullOrEmpty()) { subscription.CustomerOrders = subscriptionOrders.Where(x => x.SubscriptionId == subscription.Id).ToList(); subscription.CustomerOrdersIds = subscription.CustomerOrders.Select(x => x.Id).ToArray(); } } return(retVal.ToArray()); }
public IHttpActionResult UpdateOrders(string action, string order_number, string carrier, string service, string tracking_number, ShipNotice shipnotice) { var searchCriteria = new CustomerOrderSearchCriteria { Number = shipnotice.OrderNumber, ResponseGroup = "Full" }; var order = _orderSearchService.SearchCustomerOrders(searchCriteria); if (order == null) { return(BadRequest("Order not found")); } var updatedOrder = _orderService.GetByIds(new[] { order.Results.FirstOrDefault().Id }).FirstOrDefault(); if (updatedOrder != null) { updatedOrder.Patch(shipnotice); _orderService.SaveChanges(new[] { updatedOrder }); } return(Ok(shipnotice)); }
public virtual orderModel.CustomerOrder PlaceCustomerOrderFromCart(cartModel.ShoppingCart cart) { var customerOrder = ConvertCartToOrder(cart); _customerOrderService.SaveChanges(new[] { customerOrder }); customerOrder = _customerOrderService.GetByIds(new[] { customerOrder.Id }).FirstOrDefault(); return(customerOrder); }
public async Task <IHttpActionResult> GetById(string id, [FromUri] string respGroup = null) { var userName = User.Identity.Name; var user = await _securityService.FindByNameAsync(userName, UserDetails.Reduced); respGroup = OrderReadPricesPermission.ApplyResponseGroupFiltering(user, _securityService.GetUserPermissions(userName), respGroup); var result = _customerOrderService.GetByIds(new[] { id }, respGroup).FirstOrDefault(); if (result == null) { return(NotFound()); } //Scope bound security check var scopes = _permissionScopeService.GetObjectPermissionScopeStrings(result).ToArray(); if (!_securityService.UserHasAnyPermission(User.Identity.Name, scopes, OrderPredefinedPermissions.Read)) { throw new HttpResponseException(HttpStatusCode.Unauthorized); } //Set scopes for UI scope bounded ACL checking result.Scopes = scopes; return(Ok(result)); }
public IHttpActionResult GetById(string id) { var retVal = _customerOrderService.GetByIds(new[] { id }, CustomerOrderResponseGroup.Full.ToString()).FirstOrDefault(); if (retVal == null) { return(NotFound()); } //Scope bound security check var scopes = _permissionScopeService.GetObjectPermissionScopeStrings(retVal).ToArray(); if (!_securityService.UserHasAnyPermission(User.Identity.Name, scopes, OrderPredefinedPermissions.Read)) { throw new HttpResponseException(HttpStatusCode.Unauthorized); } //Set scopes for UI scope bounded ACL checking retVal.Scopes = scopes; return(Ok(retVal)); }
public IHttpActionResult RegisterPayment(string orderId) { var order = _customerOrderService.GetByIds(new[] { orderId }).FirstOrDefault(); if (order == null) { throw new NullReferenceException("order"); } var store = _storeService.GetById(order.StoreId); var parameters = new NameValueCollection(); foreach (var key in HttpContext.Current.Request.QueryString.AllKeys) { parameters.Add(key, HttpContext.Current.Request.Form[key]); } foreach (var key in HttpContext.Current.Request.Form.AllKeys) { parameters.Add(key, HttpContext.Current.Request.Form[key]); } var paymentMethod = store.PaymentMethods.FirstOrDefault(x => x.Code == "AuthorizeNet"); if (paymentMethod != null) { var validateResult = paymentMethod.ValidatePostProcessRequest(parameters); var paymentOuterId = validateResult.OuterId; var payment = order.InPayments.FirstOrDefault(x => x.GatewayCode == "AuthorizeNet" && x.Sum == Convert.ToDecimal(parameters["x_amount"], CultureInfo.InvariantCulture)); if (payment == null) { throw new NullReferenceException("payment"); } if (payment == null) { throw new NullReferenceException("appropriate paymentMethod not found"); } var context = new PostProcessPaymentEvaluationContext { Order = order, Payment = payment, Store = store, OuterId = paymentOuterId, Parameters = parameters }; var retVal = paymentMethod.PostProcessPayment(context); if (retVal != null && retVal.IsSuccess) { _customerOrderService.SaveChanges(new CustomerOrder[] { order }); var returnHtml = string.Format("<html><head><script type='text/javascript' charset='utf-8'>window.location='{0}';</script><noscript><meta http-equiv='refresh' content='1;url={0}'></noscript></head><body></body></html>", retVal.ReturnUrl); return(Ok(returnHtml)); } } return(StatusCode(System.Net.HttpStatusCode.NoContent)); }