public bool TryValidateReturn(PurchaseOrder order, ReturnInfo returnInfo, out string[] messages) { bool isValid = true; var errors = new List <string>(); if (order.ReturnOrderForms.ToArray().Any(f => f.Status == ReturnFormStatus.AwaitingStockReturn.ToString() || f.Status == ReturnFormStatus.AwaitingCompletion.ToString())) { errors.Add(string.Format("Order {0} has pending returns", order.TrackingNumber)); } var returnableLineItems = ReturnExchangeManager.GetAvailableForReturnLineItems(order.OrderForms[0].Shipments[0]).ToList(); foreach (ReturnItem returnItem in returnInfo.ReturnItems) { if (returnableLineItems.All(x => x.CatalogEntryId != returnItem.Sku)) { errors.Add(string.Format("Lineitem with code: {0} is not returnable", returnItem.Sku)); } } messages = errors.ToArray(); if (errors.Any()) { isValid = false; } return(isValid); }
public HttpResponseMessage CreateReturn(ReturnInfo returnInfo) { var returFormCalculator = ServiceLocator.Current.GetInstance <IReturnFormTotalCalculator>(); var paymentCreator = ServiceLocator.Current.GetInstance <ICreditPaymentCreator>(); var paymentRetriever = ServiceLocator.Current.GetInstance <IOrderFormPaymentRetriever>(); var returnOrderValidator = ServiceLocator.Current.GetInstance <IReturnOrderValidator>(); var order = Get(returnInfo.OrderNumber); string[] messages; if (!returnOrderValidator.TryValidateReturn(order, returnInfo, out messages)) { return(CreateResponseMessage(HttpStatusCode.NotAcceptable, string.Join(", ", messages))); } var returnForm = ReturnExchangeManager.AddNewReturnFormToPurchaseOrder(order); foreach (var item in returnInfo.ReturnItems) { var returnableLineItems = ReturnExchangeManager.GetAvailableForReturnLineItems(order.OrderForms[0].Shipments[0]).Where(l => l.CatalogEntryId == item.Sku).ToList(); ReturnExchangeManager.AddNewReturnLineItemToReturnForm(returnForm, returnableLineItems.FirstOrDefault(), item.Quantity, item.ReturnReason); ReturnExchangeManager.AddNewShipmetToReturnForm(returnForm, order.OrderForms[0].Shipments[0]); } ReturnFormStatusManager.AcknowledgeReceiptItems(returnForm); returFormCalculator.AdjustReturnTotal(returnForm); paymentCreator.CreateCreditPayment <OtherPayment>(returnForm, order, paymentRetriever.GetCapturedPayment(order).PaymentMethodId); order.AcceptChanges(); var respons = CreateResponseMessage(HttpStatusCode.OK, "Return Created"); return(respons); }