public QuoteRequestTotals CalculateTotals(QuoteRequest quote)
        {
            var retVal = new QuoteRequestTotals();
            var cartFromQuote = quote.ToCartModel();
            var store = _storeService.GetById(quote.StoreId);

            if (store != null)
            {
                //Calculate shipment total
                //firts try to get manual amount
                retVal.ShippingTotal = quote.ManualShippingTotal;
                if (retVal.ShippingTotal == 0 && quote.ShipmentMethod != null)
                {
                    //calculate total by using shipment gateways
                    var evalContext = new ShippingEvaluationContext(cartFromQuote);

                    var rate = store.ShippingMethods.Where(x => x.IsActive && x.Code == quote.ShipmentMethod.ShipmentMethodCode)
                                                    .SelectMany(x => x.CalculateRates(evalContext))
                                                    .Where(x => quote.ShipmentMethod.OptionName != null ? quote.ShipmentMethod.OptionName == x.OptionName : true)
                                                    .FirstOrDefault();
                    retVal.ShippingTotal = rate != null ? rate.Rate : 0m;
                }
                //Calculate taxes
                var taxProvider = store.TaxProviders.Where(x => x.IsActive).OrderBy(x => x.Priority).FirstOrDefault();
                if (taxProvider != null)
                {
                    var taxRequest = quote.ToTaxRequest();
                    var taxEvalContext = new TaxEvaluationContext(taxRequest);
                    retVal.TaxTotal = taxProvider.CalculateRates(taxEvalContext).Select(x => x.Rate).DefaultIfEmpty(0).Sum(x => x);
                }
            }

            //Calculate subtotal
            var items = quote.Items.Where(x => x.SelectedTierPrice != null);
            if (quote.Items != null)
            {
                retVal.OriginalSubTotalExlTax = items.Sum(x => x.SalePrice * x.SelectedTierPrice.Quantity);
                retVal.SubTotalExlTax = items.Sum(x => x.SelectedTierPrice.Price * x.SelectedTierPrice.Quantity);
                if (quote.ManualSubTotal > 0)
                {
                    retVal.DiscountTotal = retVal.SubTotalExlTax - quote.ManualSubTotal;
                    retVal.SubTotalExlTax = quote.ManualSubTotal;
                }
                else if (quote.ManualRelDiscountAmount > 0)
                {
                    retVal.DiscountTotal = retVal.SubTotalExlTax * quote.ManualRelDiscountAmount * 0.01m;
                }
            }

            return retVal;
        }
		public IHttpActionResult GetShipmentMethods(string cartId)
		{
			var cart = _shoppingCartService.GetById(cartId);
			var store = _storeService.GetById(cart.StoreId);
			var evalContext = new ShippingEvaluationContext(cart);

			var retVal = store.ShippingMethods.Where(x => x.IsActive).SelectMany(x => x.CalculateRates(evalContext))
				.Select(x => new webModel.ShippingMethod
				{
					Currency = cart.Currency,
					Name = x.ShippingMethod.Description,
					OptionName = x.OptionName,
					OptionDescription = x.OptionDescription,
					Price = x.Rate,
					ShipmentMethodCode = x.ShippingMethod.Code,
					LogoUrl = x.ShippingMethod.LogoUrl,
					TaxType = x.ShippingMethod.TaxType
				});
			
			return Ok(retVal);
		}
        public IHttpActionResult GetShipmentMethods(string id)
        {
            var quote = _quoteRequestService.GetByIds(id).FirstOrDefault();
            if (quote != null)
            {
                var store = _storeService.GetById(quote.StoreId);

                if (store != null)
                {
                    var cartFromQuote = quote.ToCartModel();
                    var evalContext = new ShippingEvaluationContext(cartFromQuote);
                    var rates = store.ShippingMethods.Where(x => x.IsActive).SelectMany(x => x.CalculateRates(evalContext)).ToArray();
                    var retVal = rates.Select(x => new webModel.ShipmentMethod
                    {
                        Currency = x.Currency,
                        Name = x.ShippingMethod.Name,
                        Price = x.Rate,
                        OptionName = x.OptionName,
                        ShipmentMethodCode = x.ShippingMethod.Code,
                        LogoUrl = x.ShippingMethod.LogoUrl
                    }).ToArray();

                    return Ok(retVal);
                }
            }
            return NotFound();
        }
        public IHttpActionResult GetShipmentMethods(string cartId)
        {
            var cart = _shoppingCartService.GetById(cartId);
            var store = _storeService.GetById(cart.StoreId);
            var evalContext = new ShippingEvaluationContext(cart);

            var retVal = store.ShippingMethods.Where(x => x.IsActive)
                                              .SelectMany(x => x.CalculateRates(evalContext))
                                              .Select(x => x.ToWebModel()).ToArray();

            return Ok(retVal);
        }