public TestOrderBuilder WithReturns()
		{
			var returnLineItems = _order.OrderForms[0].LineItems.Take(2).ToArray();

			var returnItem1 = new RmaReturnItem
				{
					ItemState = RmaLineItemState.AwaitingReturn.ToString(),
					ReturnAmount = 21.32m,
					ReturnReason = "Corrupt"
				};

			var rmaLineItem = new RmaLineItem
				{
					RmaReturnItemId = returnItem1.RmaReturnItemId,
					LineItemId = returnLineItems[0].LineItemId,
					LineItem = returnLineItems[0],
					ReturnQuantity = 1,
					Quantity = 0
				};
			returnItem1.RmaLineItems.Add(rmaLineItem);

			var returnItem2 = new RmaReturnItem
				{
					ItemState = RmaLineItemState.AwaitingReturn.ToString(),
					ReturnAmount = 210.67m,
					ReturnReason = "Other"
				};

			rmaLineItem = new RmaLineItem
				{
					RmaReturnItemId = returnItem2.RmaReturnItemId,
					LineItemId = returnLineItems[1].LineItemId,
					LineItem = returnLineItems[1],
					ReturnQuantity = 2,
					Quantity = 0
				};
			returnItem2.RmaLineItems.Add(rmaLineItem);

			var rmaRequest = new RmaRequest
				{
                    Status = RmaRequestStatus.AwaitingStockReturn.ToString(),
					ReturnTotal = 323.21m,
					RefundAmount = 301.89m,
					OrderId = _order.OrderGroupId
				};

			foreach (var rmaItem in new[] { returnItem1, returnItem2 })
			{
				rmaRequest.RmaReturnItems.Add(rmaItem);
			}
			((Order)_order).RmaRequests.Add(rmaRequest);
			return this;
		}
        public ActionResult OrderReturn(OrderReturns model)
        {
            var order = _orderClient.GetCustomerOrder(UserHelper.CustomerSession.CustomerId, model.OrderId);

            if (order == null || String.IsNullOrEmpty(order.CustomerId))
            {
                throw new UnauthorizedAccessException();
            }

            InitReturnsModel(order, model);

            //Filter validation only for selected items
            var selectedReturnItems = new List<OrderReturnItem>();
            for (var i = 0; i < model.OrderReturnItems.Count; i++)
            {
                if (model.OrderReturnItems[i].IsSelected)
                {
                    selectedReturnItems.Add(model.OrderReturnItems[i]);
                    continue;
                }
                var i1 = i;
                foreach (var k in ModelState.Keys.Where(k => k.StartsWith(string.Format("OrderReturnItems[{0}]", i1))).ToArray())
                {
                    ModelState.Remove(k);
                }
            }

            //No items to return
            if (selectedReturnItems.Count == 0)
            {
                ModelState.AddModelError("", @"Select at least one item to return");
            }

            //If Validation passed create RmaReturns
            if (ModelState.IsValid)
            {
                var request = new RmaRequest
                {
                    Comment = model.Comment,
                    OrderId = model.OrderId,
                    Status = RmaRequestStatus.AwaitingStockReturn.ToString(),
                    ReturnFromAddressId = model.ReturnFromAddressId
                };
                request.AuthorizationCode = request.RmaRequestId;

                foreach (var item in selectedReturnItems)
                {
                    var rmali = new RmaLineItem
                    {
                        LineItemId = item.LineItemId,
                        LineItem = order.OrderForms.SelectMany(of => of.LineItems).Single(li => li.LineItemId == item.LineItemId),
                        ReturnQuantity = item.Quantity
                    };

                    var rmaritem = new RmaReturnItem
                    {
                        ItemState = RmaLineItemState.AwaitingReturn.ToString(),
                        ReturnReason = item.ReturnReason,
                        //ReturnAmount = item.LineItemModel.LineItem.ListPrice
                    };

                    rmaritem.RmaLineItems.Add(rmali);
                    request.RmaReturnItems.Add(rmaritem);
                }

                order.RmaRequests.Add(request);

                //Calculate return totals
                _orderService.ExecuteWorkflow("CalculateReturnTotalsWorkflow", order);
                //Save changes
                _orderClient.SaveChanges();

                return RedirectToAction("RmaReturns", new { orderId = model.OrderId });
            }

            return View(model);
        }