public HttpResponseMessage AddShipMethod(ShipMethodDisplay method)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                var provider = _shippingContext.CreateInstance(method.ProviderKey);

                var gatewayResource =
                    provider.ListResourcesOffered().FirstOrDefault(x => x.ServiceCode == method.ServiceCode);

                var shipCountry = _shipCountryService.GetByKey(method.ShipCountryKey);

                var shippingGatewayMethod = provider.CreateShippingGatewayMethod(gatewayResource, shipCountry, method.Name);

                provider.SaveShippingGatewayMethod(shippingGatewayMethod);

            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, String.Format("{0}", ex.Message));
            }

            return response;
        }
        internal static IShipMethod ToShipMethod(this ShipMethodDisplay shipMethodDisplay, IShipMethod destination)
        {
            if (shipMethodDisplay.Key != Guid.Empty)
            {
                destination.Key = shipMethodDisplay.Key;
            }
            destination.Name        = shipMethodDisplay.Name;
            destination.ServiceCode = shipMethodDisplay.ServiceCode;
            destination.Surcharge   = shipMethodDisplay.Surcharge;
            destination.Taxable     = shipMethodDisplay.Taxable;

            foreach (var shipProvinceDisplay in shipMethodDisplay.Provinces)
            {
                IShipProvince destinationShipProvince;

                var matchingItems = destination.Provinces.Where(x => x.Code == shipProvinceDisplay.Code);
                var shipProvinces = matchingItems as IShipProvince[] ?? matchingItems.ToArray();
                if (shipProvinces.Any())
                {
                    var existingShipProvince = shipProvinces.First();
                    if (existingShipProvince != null)
                    {
                        destinationShipProvince = existingShipProvince;

                        destinationShipProvince = shipProvinceDisplay.ToShipProvince(destinationShipProvince);
                    }
                }
            }

            return(destination);
        }
        public HttpResponseMessage PutShipMethod(ShipMethodDisplay method)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                var provider = _shippingContext.CreateInstance(method.ProviderKey);

                var shippingMethod = provider.ShipMethods.FirstOrDefault(x => x.Key == method.Key);

                shippingMethod = method.ToShipMethod(shippingMethod);

                provider.GatewayProviderService.Save(shippingMethod);
            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, String.Format("{0}", ex.Message));
            }

            return response;
        }
        public HttpResponseMessage DeleteShipMethod(ShipMethodDisplay method)
        {
            var shippingMethodService = ((ServiceContext)MerchelloContext.Services).ShipMethodService;
            var methodToDelete = shippingMethodService.GetByKey(method.Key);

            if (methodToDelete == null) return Request.CreateResponse(HttpStatusCode.NotFound);

            shippingMethodService.Delete(methodToDelete);

            return Request.CreateResponse(HttpStatusCode.OK);
        }
 public ShipMethodDisplay AddShipMethod(ShipMethodDisplay method)
 {
     return null;
 }
 public ShipMethodDisplay DeleteShipMethod(ShipMethodDisplay method)
 {
     return null;
 }