// Get Shipping Address by Customer Id
        /// <summary>
        /// Get all Shipping Addresses associated with a Customer ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IHttpActionResult Get(int id)
        {
            ShippingAddressService shippingAddressService = CreateShippingAddressService();
            var shippingAddresses = shippingAddressService.GetShippingAddressesByCustomerId(id);

            return(Ok(shippingAddresses));
        }
        // Get Shipping Address
        /// <summary>
        /// Get All Shipping Addresses for all Customers
        /// </summary>
        /// <returns></returns>
        public IHttpActionResult Get()
        {
            ShippingAddressService shippingAddressService = CreateShippingAddressService();
            var shippingAddresses = shippingAddressService.GetShippingAddresses();

            return(Ok(shippingAddresses));
        }
        //Establish connection
        private ShippingAddressService CreateShippingAddressService()
        {
            var userId = Guid.Parse(User.Identity.GetUserId());
            var ShippingAddressService = new ShippingAddressService(userId);

            return(ShippingAddressService);
        }
        public HttpResponseMessage GetShippingAddress()
        {
            ShippingAddressService shippingaddressservice = new ShippingAddressService();
            List <ShippingAddress> shippingaddress        = shippingaddressservice.Read();
            string shippingaddressJSON = JsonConvert.SerializeObject(shippingaddress, Formatting.Indented);
            var    response            = Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new StringContent(shippingaddressJSON, Encoding.UTF8, "application/json");
            return(response);
        }
        /// <summary>
        /// Delete a Shipping Address from the database
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IHttpActionResult DeleteShippingAddress(int id)
        {
            ShippingAddressService service = CreateShippingAddressService();

            var shippingAddresses = service.DeleteShippingAddress(id);

            if (shippingAddresses == true)
            {
                return(Ok(shippingAddresses));
            }
            return(InternalServerError());
        }
        public HttpResponseMessage GetShippingAddress(string key)
        {
            HttpResponseMessage    response = new HttpResponseMessage(HttpStatusCode.Unused);
            ShippingAddressService shippingaddressservice = new ShippingAddressService();
            List <ShippingAddress> shippingAddress        = shippingaddressservice.Read();
            int id = shippingaddressservice.GetIndex(key);

            if (id != -1)
            {
                ShippingAddress sa = shippingAddress[id];
                string          shippingaddressJSON = JsonConvert.SerializeObject(sa, Formatting.Indented);
                response         = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = new StringContent(shippingaddressJSON, Encoding.UTF8, "application/json");
            }
            else
            {
                response         = new HttpResponseMessage(HttpStatusCode.ExpectationFailed);
                response.Content = new StringContent("Error", Encoding.UTF8, "application/json");
            }
            return(response);
        }
        public HttpResponseMessage DeleteShippingAddress(string id)
        {
            var response = Request.CreateResponse(HttpStatusCode.Unused);

            try
            {
                ShippingAddressService sas = new ShippingAddressService();
                if (sas.Delete(id))
                {
                    response = new HttpResponseMessage(HttpStatusCode.OK);
                }
                else
                {
                    response = new HttpResponseMessage(HttpStatusCode.ExpectationFailed);
                }
            }
            catch
            {
                response = new HttpResponseMessage(HttpStatusCode.ExpectationFailed);
            }
            return(response);
        }
        public HttpResponseMessage UpdateShippingAddress(Object content, string key)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Unused);

            try
            {
                ShippingAddress        shippingaddress = JsonConvert.DeserializeObject <ShippingAddress>(content.ToString());
                ShippingAddressService sas             = new ShippingAddressService();
                if (sas.Update(key, shippingaddress))
                {
                    response = new HttpResponseMessage(HttpStatusCode.OK);
                }
                else
                {
                    response = new HttpResponseMessage(HttpStatusCode.ExpectationFailed);
                }
            }
            catch
            {
                response = new HttpResponseMessage(HttpStatusCode.ExpectationFailed);
            }
            return(response);
        }
        public HttpResponseMessage PostShippingAddress(Object content)
        {
            HttpResponseMessage ms = new HttpResponseMessage(HttpStatusCode.Unused);

            try
            {
                String                 shippingaddressJSON = content.ToString();
                ShippingAddress        shippingaddress     = JsonConvert.DeserializeObject <ShippingAddress>(shippingaddressJSON);
                ShippingAddressService sas = new ShippingAddressService();
                if (sas.Create(shippingaddress))
                {
                    ms = new HttpResponseMessage(HttpStatusCode.OK);
                }
                else
                {
                    ms = new HttpResponseMessage(HttpStatusCode.ExpectationFailed);
                }
            }
            catch
            {
                ms = new HttpResponseMessage(HttpStatusCode.Unused);
            }
            return(ms);
        }