Exemplo n.º 1
0
        public void Update_Test()
        {
            Address       address       = new Address();
            StateProvince stateProvince = new StateProvince();

            address = _addressService.Get(1);

            //Arrange
            int userId = 1;
            AddressUpdateRequest addressUpdate = new AddressUpdateRequest
            {
                Id         = address.Id,
                LineOne    = "1382 Emir St",
                LineTwo    = "",
                City       = "Green Bay",
                StateId    = 50,
                PostalCode = "54313",
            };

            //Act
            _addressService.Update(addressUpdate, userId);
            Address newAddress = new Address();

            newAddress.StateProvince = new StateProvince();
            newAddress = _addressService.Get(1);

            //Assert
            Assert.IsTrue(address.Id == newAddress.Id, "Id doesn't match");
            Assert.IsFalse(address.LineOne == newAddress.LineOne, "LineOne hasn't changed");
            Assert.IsFalse(address.LineTwo == newAddress.LineTwo, "LineOne hasn't changed");
            Assert.IsFalse(address.City == newAddress.City, "LineOne hasn't changed");
            Assert.IsFalse(address.StateProvince.Id == newAddress.StateProvince.Id, "LineOne hasn't changed");
            Assert.IsFalse(address.PostalCode == newAddress.PostalCode, "LineOne hasn't changed");
        }
Exemplo n.º 2
0
        public int SaveWebsiteAddress(WebsiteAddRequest model)
        {
            var addressId = model.AddressId;
            AddressAddRequest    newAddress = new AddressAddRequest();
            AddressUpdateRequest Address    = new AddressUpdateRequest();

            if (addressId > 0)
            {
                Address.Name            = model.Name;
                Address.AddressId       = model.AddressId;
                Address.ExternalPlaceId = model.ExternalAddressId;
                Address.Line1           = model.Street;
                Address.City            = model.City;
                Address.State           = model.State;
                Address.ZipCode         = model.ZipCode;
                Address.Country         = model.Country;

                Update(Address);
            }
            else
            {
                newAddress.Name            = model.Name;
                newAddress.ExternalPlaceId = model.ExternalAddressId;
                newAddress.Line1           = model.Street;
                newAddress.City            = model.City;
                newAddress.State           = model.State;
                newAddress.ZipCode         = model.ZipCode;
                newAddress.Country         = model.Country;

                addressId = Insert(newAddress);
            }

            return(addressId);
        }
Exemplo n.º 3
0
        public AddressUpdateResponse UpdateAddress(ICart cart, AddressUpdateRequest addressUpdateRequest)
        {
            var configuration = GetConfiguration(cart.Market);
            var shipment      = cart.GetFirstShipment();

            if (shipment != null)
            {
                shipment.ShippingAddress = addressUpdateRequest.ShippingAddress.ToOrderAddress(cart);
                _orderRepository.Save(cart);
            }

            var totals = _orderGroupTotalsCalculator.GetTotals(cart);
            var result = new AddressUpdateResponse
            {
                OrderAmount      = AmountHelper.GetAmount(totals.Total),
                OrderTaxAmount   = AmountHelper.GetAmount(totals.TaxTotal),
                OrderLines       = GetOrderLines(cart, totals, configuration.SendProductAndImageUrl),
                PurchaseCurrency = cart.Currency.CurrencyCode,
                ShippingOptions  = configuration.ShippingOptionsInIFrame ? GetShippingOptions(cart, cart.Currency, ContentLanguage.PreferredCulture) : Enumerable.Empty <ShippingOption>()
            };

            if (ServiceLocator.Current.TryGetExistingInstance(out ICheckoutOrderDataBuilder checkoutOrderDataBuilder))
            {
                checkoutOrderDataBuilder.Build(result, cart, configuration);
            }
            return(result);
        }
Exemplo n.º 4
0
        public async Task <int> Update(AddressUpdateRequest request)
        {
            var a = await db.Ib_addresses.FindAsync(request.Ib_record_primary_key);

            if (a == null)
            {
                throw new LinxOneException($"Cannot find an address with id{request.Ib_record_primary_key}");
            }

            var adderss = new Ib_address()
            {
                Ib_record_primary_key           = request.Ib_record_primary_key,
                Ib_customer_address_city        = request.Ib_customer_address_city,
                Ib_customer_address_line_1      = request.Ib_customer_address_line_1,
                Ib_customer_address_line_2      = request.Ib_customer_address_line_2,
                Ib_customer_address_phone_1     = request.Ib_customer_address_phone_1,
                Ib_customer_address_phone_2     = request.Ib_customer_address_phone_2,
                Ib_customer_address_postal_code = request.Ib_customer_address_postal_code,
                Ib_customer_address_state       = request.Ib_customer_address_state,
                Ib_customer_address_website_url = request.Ib_customer_address_website_url,
                Ib_customer_id = request.Ib_customer_id,
            };

            db.Ib_addresses.Update(adderss);
            return(await db.SaveChangesAsync());
        }
Exemplo n.º 5
0
        public IHttpActionResult AddressUpdate(int orderGroupId, [FromBody] AddressUpdateRequest addressUpdateRequest)
        {
            var cart     = _orderRepository.Load <ICart>(orderGroupId);
            var response = _klarnaCheckoutService.UpdateAddress(cart, addressUpdateRequest);

            return(Ok(response));
        }
Exemplo n.º 6
0
        public void Update(AddressUpdateRequest model)
        {
            DataProvider.ExecuteNonQuery(GetConnection, "dbo.Addresses_Update",
                                         inputParamMapper : delegate(SqlParameterCollection parameters)
            {
                parameters.AddWithValue("@Id", model.Id);
                parameters.AddWithValue("@UserId", model.UserId);
                parameters.AddWithValue("@Name", model.Name);

                if (model.Street == null)
                {
                    parameters.AddWithValue("@Street", DBNull.Value);
                }
                else
                {
                    parameters.AddWithValue("@Street", model.Street);
                }

                if (model.Street2 == null)
                {
                    parameters.AddWithValue("@Street2", DBNull.Value);
                }
                else
                {
                    parameters.AddWithValue("@Street2", model.Street2);
                }

                if (model.City == null)
                {
                    parameters.AddWithValue("@City", DBNull.Value);
                }
                else
                {
                    parameters.AddWithValue("@City", model.City);
                }

                if (model.State == null)
                {
                    parameters.AddWithValue("@State", DBNull.Value);
                }
                else
                {
                    parameters.AddWithValue("@State", model.State);
                }

                if (model.PostalCode == null)
                {
                    parameters.AddWithValue("@PostalCode", DBNull.Value);
                }
                else
                {
                    parameters.AddWithValue("@PostalCode", model.PostalCode);
                }
            });
        }
Exemplo n.º 7
0
        [Route("{id:int}"), HttpPut]                                                        //its taking my URL/Ajax/settings into the route  //HTTP Put is the only request at this point
        public HttpResponseMessage UpdateAddresses(AddressUpdateRequest model, int id)      //creating a name for HTTPResponseMessage >> UpdateAddresses
        {                                                                                   //in the parameters includes the model and id >> it is being passed as a numeric id
            if (!ModelState.IsValid)                                                        //if my data is NOT valid
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); //it will return as error response
            }

            SucessResponse response = new SucessResponse();

            _addressService.Update(model);                    //packaging data from your database
            return(Request.CreateResponse(response));         //and sends it right back to your Ajax becasue the functions are there
        }
        public HttpResponseMessage Update(AddressUpdateRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(CreateErrorResponse());
            }
            int userId = _auth.GetCurrentUserId();

            _service.Update(model, userId);
            SuccessResponse response = new SuccessResponse();

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Exemplo n.º 9
0
 public void Update(AddressUpdateRequest model)
 {
     DataProvider.ExecuteNonQuery(GetConnection, "dbo.Addresses_Update"
                                  , inputParamMapper : delegate(SqlParameterCollection AddressesUpdate)
     {
         AddressesUpdate.AddWithValue("@Id", model.Id);
         AddressesUpdate.AddWithValue("@Line1", model.Line1);
         AddressesUpdate.AddWithValue("@Line2", model.Line2);
         AddressesUpdate.AddWithValue("@City", model.City);
         AddressesUpdate.AddWithValue("@StateProvinceId", model.StateProvinceId);
         AddressesUpdate.AddWithValue("@ZipCode", model.ZipCode);
     });
 }
        public HttpResponseMessage Update(int AddressId, AddressUpdateRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            _AddressService.UpdateForLatAndLong(model);
            ItemResponse <bool> response = new ItemResponse <bool>();

            response.Item = true;

            return(Request.CreateResponse(response));
        }
Exemplo n.º 11
0
 public void Update(AddressUpdateRequest model)
 {
     DataProvider.ExecuteNonQuery("dbo.Address_Update",
                                  inputParamMapper: (SqlParameterCollection inputs) =>
     {
         inputs.AddWithValue("@Id", model.Id);
         inputs.AddWithValue("@AddressTypeId", model.AddressTypeId);
         inputs.AddWithValue("@StreetAddress", model.StreetAddress);
         inputs.AddWithValue("@City", model.City);
         inputs.AddWithValue("@StateProvinceId", model.StateProvinceId);
         inputs.AddWithValue("@PostalCode", model.PostalCode);
         inputs.AddWithValue("@Latitude", model.Latitude);
         inputs.AddWithValue("@Longitude", model.Longitude);
     });
 }
Exemplo n.º 12
0
        public HttpResponseMessage AddressEdit(AddressUpdateRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            bool isSuccessful = _AddressService.UpdateAddress(model);

            var response = new ItemResponse <bool> {
                Item = isSuccessful
            };

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Exemplo n.º 13
0
 public void Update(AddressUpdateRequest model)
 {
     _dataProvider.ExecuteNonQuery("Addresses_Update", inputParamMapper : delegate(SqlParameterCollection parms)
     {
         parms.AddWithValue("@Id", model.Id);
         parms.AddWithValue("@AddressTypeId", model.AddressTypeId);
         parms.AddWithValue("@LineOne", model.LineOne);
         parms.AddWithValue("@LineTwo", model.LineTwo);
         parms.AddWithValue("@City", model.City);
         parms.AddWithValue("@Zip", model.Zip);
         parms.AddWithValue("@StateId", model.StateId);
         parms.AddWithValue("@Latitude", model.Latitude);
         parms.AddWithValue("@Longitude", model.Longitude);
     });
 }
Exemplo n.º 14
0
 public void Update(AddressUpdateRequest model)
 {
     DataProvider.ExecuteNonQuery(GetConnection, "dbo.Address_Update",
                                  inputParamMapper : delegate(SqlParameterCollection paramCollection)
     {
         paramCollection.AddWithValue("@UserId", model.UserId);
         paramCollection.AddWithValue("@Name", model.Name);
         paramCollection.AddWithValue("@ExternalPlaceId", model.ExternalPlaceId);
         paramCollection.AddWithValue("@Line1", model.Line1);
         paramCollection.AddWithValue("@Line2", model.Line2);
         paramCollection.AddWithValue("@City", model.City);
         paramCollection.AddWithValue("@StateId", model.StateId);
         paramCollection.AddWithValue("@ZipCode", model.ZipCode);
         paramCollection.AddWithValue("@Country", model.Country);
         paramCollection.AddWithValue("@AddressId", model.AddressId);
         paramCollection.AddWithValue("@Latitude", model.Latitude);
         paramCollection.AddWithValue("@Longitude", model.Longitude);
     });
 }
Exemplo n.º 15
0
        public void Update(AddressUpdateRequest data, int userId)
        {
            if (data == null)
            {
                throw new ArgumentNullException("Parameter data is required");
            }
            string storedProc = "[dbo].[Addresses_Update]";

            _dataProvider.ExecuteNonQuery(storedProc,

                                          delegate(SqlParameterCollection sqlParams)
            {
                sqlParams.AddWithValue("@Id", data.Id);
                sqlParams.AddWithValue("@LineOne", data.LineOne);
                sqlParams.AddWithValue("@LineTwo", data.LineTwo);
                sqlParams.AddWithValue("@City", data.City);
                sqlParams.AddWithValue("@StateId", data.StateId);
                sqlParams.AddWithValue("@PostalCode", data.PostalCode);
            });
        }
Exemplo n.º 16
0
        public int SaveWaypointAddress(WaypointRequest model)
        {
            var addressId = 0;

            AddressAddRequest newAddress = new AddressAddRequest();

            Address CurrentAddress = GetByExternalAddressId(model.Address.ExternalPlaceId);

            if (CurrentAddress == null)
            {
                model.Address.Name = model.ContactName;

                addressId = Insert(model.Address);
            }
            else
            {
                AddressUpdateRequest Address = new AddressUpdateRequest();

                Address.AddressId       = CurrentAddress.AddressId;
                Address.Name            = model.ContactName;
                Address.ExternalPlaceId = model.Address.ExternalPlaceId;
                Address.Line1           = model.Address.Line1;
                Address.City            = model.Address.City;
                Address.State           = model.Address.State;
                Address.ZipCode         = model.Address.ZipCode;

                if (model.Address.Latitude != null && model.Address.Latitude > 0)
                {
                    Address.Latitude = model.Address.Latitude;
                }
                if (model.Address.Longitude != null && model.Address.Longitude > 0)
                {
                    Address.Longitude = model.Address.Longitude;
                }

                Update(Address);
                addressId = CurrentAddress.AddressId;
            }

            return(addressId);
        }
Exemplo n.º 17
0
 public ActionResult <SuccessResponse> Update(int id, AddressUpdateRequest model)
 {
     try
     {
         if (id == model.Id)
         {
             _addressService.Update(model);
             SuccessResponse resp = new SuccessResponse();
             return(Ok200(resp));
         }
         else
         {
             return(NotFound404(new ErrorResponse("Bad Request: Body Id does not match entity")));
         }
     }
     catch (Exception ex)
     {
         Logger.LogError(ex.ToString());
         return(StatusCode(500, new ErrorResponse(ex.Message)));
     }
 }
Exemplo n.º 18
0
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        public bool UpdateAddress(AddressUpdateRequest model)
        {
            bool success = false;

            string addressString = String.Concat(model.Address1, ", ", model.City, ",  "
                                                 , model.State, ", ", model.ZipCode);

            LatLngDomain latlng = AddressGetLatLng(addressString);

            model.Latitude  = latlng.Latitude;
            model.Longitude = latlng.Longitude;


            try
            {
                DataProvider.ExecuteNonQuery(GetConnection, "dbo.Address_Update"
                                             , inputParamMapper : delegate(SqlParameterCollection paramCollection)
                {
                    paramCollection.AddWithValue("@CompanyId", model.CompanyId);
                    paramCollection.AddWithValue("@Date", model.Date);
                    paramCollection.AddWithValue("@Address1", model.Address1);
                    paramCollection.AddWithValue("@City", model.City);
                    paramCollection.AddWithValue("@State", model.State);
                    paramCollection.AddWithValue("@ZipCode", model.ZipCode);
                    paramCollection.AddWithValue("@Latitude", model.Latitude);
                    paramCollection.AddWithValue("@Longitude", model.Longitude);
                    paramCollection.AddWithValue("@Slug", model.Slug);
                    paramCollection.AddWithValue("@AddressType", model.AddressType);
                    paramCollection.AddWithValue("@Id", model.AddressId);

                    success = true;
                });
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

            return(success);
        }
        /// <summary>
        /// Update the account holder's current address
        /// </summary>
        /// <param name="body">Required parameter: Update account holder's current address</param>
        /// <return>Returns the void response from the API call</return>
        public async Task UpdateCurrentAddressAsync(AddressUpdateRequest body)
        {
            //validating required parameters
            if (null == body)
            {
                throw new ArgumentNullException(nameof(body), "The parameter \"body\" is a required parameter and cannot be null.");
            }

            //the base uri for api requests
            var baseUri = Configuration.GetBaseURI();

            //prepare query string for API call
            var queryBuilder = new StringBuilder(baseUri);

            queryBuilder.Append("/api/v2/addresses");


            //validate and preprocess url
            var queryUrl = APIHelper.CleanUrl(queryBuilder);

            //append request with appropriate headers and parameters
            var headers = APIHelper.GetContentRequestHeaders();

            //append body params
            var serializedBody = APIHelper.JsonSerialize(body);

            //prepare the API call request to fetch the response
            var request = ClientInstance.PostBody(queryUrl, headers, serializedBody);

            //invoke request and get response
            var response = (HttpStringResponse)await ClientInstance.ExecuteAsStringAsync(request).ConfigureAwait(false);

            var context = new HTTPContext(request, response);

            //handle errors
            ValidateResponse(response, context);
        }
        public HttpResponseMessage Update(AddressUpdateRequest model, int userId, Guid id)
        {
            if (!IsValidRequest(model))
            {
                return(GetErrorResponse(model));
            }

            if (userId != model.UserId)
            {
                ErrorResponse error = new ErrorResponse("The userId in the route and request do not match");
                return(Request.CreateResponse(HttpStatusCode.BadRequest, error));
            }

            if (id != model.Id)
            {
                ErrorResponse error = new ErrorResponse("The Id in the route and request do not match");
                return(Request.CreateResponse(HttpStatusCode.BadRequest, error));
            }

            _addressService.Update(model);
            SuccessResponse responseData = new SuccessResponse();

            return(Request.CreateResponse(HttpStatusCode.OK, responseData));
        }
Exemplo n.º 21
0
        public AddressServiceTest()
        {
            List <Address> addressList = new List <Address>();
            Address        a1          = new Address();

            a1.StateProvince = new StateProvince();
            Address a2 = new Address();

            a2.StateProvince = new StateProvince();
            Address a3 = new Address();

            a3.StateProvince = new StateProvince();

            a1.Id               = 1;
            a1.LineOne          = "777 S. Alameda Ave";
            a1.LineTwo          = "200";
            a1.City             = "Los Angeles";
            a1.StateProvince.Id = 9;
            a1.PostalCode       = "90021";

            a2.Id               = 2;
            a2.LineOne          = "1229 N. New Hampshire Ave";
            a2.LineTwo          = "2";
            a2.City             = "Los Angeles";
            a2.StateProvince.Id = 9;
            a2.PostalCode       = "90029";

            a3.Id               = 3;
            a3.LineOne          = "1111 S. Figueroa St.";
            a3.LineTwo          = "";
            a3.City             = "Los Angeles";
            a3.StateProvince.Id = 9;
            a3.PostalCode       = "90015";

            addressList.Add(a1);
            addressList.Add(a2);
            addressList.Add(a3);

            List <AddressAddRequest> addressAddAddressList = new List <AddressAddRequest>();
            AddressAddRequest        aar1 = new AddressAddRequest();

            //int userId = 41;
            aar1.LineOne    = "777 S. Alameda Ave";
            aar1.LineTwo    = "200";
            aar1.City       = "Los Angeles";
            aar1.StateId    = 9;
            aar1.PostalCode = "90021";

            addressAddAddressList.Add(aar1);

            List <AddressUpdateRequest> addressUpdateAddressList = new List <AddressUpdateRequest>();
            AddressUpdateRequest        aur1 = new AddressUpdateRequest();

            aur1.Id         = 1;
            aur1.LineOne    = "123 Fake St.";
            aur1.LineTwo    = "4";
            aur1.City       = "New York";
            aur1.StateId    = 4;
            aur1.PostalCode = "10101";

            addressUpdateAddressList.Add(aur1);

            var mock = new Mock <IAddressService>();

            mock.Setup(m => m.Add(It.IsAny <AddressAddRequest>(), It.IsAny <int>())).Returns(
                (AddressAddRequest insertRequestModel, int userId) =>
            {
                List <ValidationResult> valididationResults = ValidateModel(insertRequestModel);

                if (valididationResults.Count > 0)
                {
                    throw new ValidationException(valididationResults[0], null, insertRequestModel);
                }
                return(addressAddAddressList.Count + 1);
            }
                );

            mock.Setup(m => m.Get(It.IsAny <int>())).Returns((int id) =>
            {
                Address model = addressList.Where(m => m.Id == id).FirstOrDefault();

                Address newModel = null;
                if (model != null)
                {
                    newModel = new Address();
                    newModel.StateProvince = new StateProvince();

                    newModel.Id               = model.Id;
                    newModel.LineOne          = model.LineOne;
                    newModel.LineTwo          = model.LineTwo;
                    newModel.City             = model.City;
                    newModel.StateProvince.Id = model.StateProvince.Id;
                    newModel.PostalCode       = model.PostalCode;
                }
                return(newModel);
            });

            mock.Setup(m => m.Update(It.IsAny <AddressUpdateRequest>(), It.IsAny <int>())).Callback(
                (AddressUpdateRequest updateRequestModel, int userId) =>
            {
                List <ValidationResult> validationResults = ValidateModel(updateRequestModel);

                if (validationResults.Count > 0)
                {
                    throw new ValidationException(validationResults[0], null, updateRequestModel);
                }
                Address model          = addressList.Where(m => m.Id == updateRequestModel.Id).Single();
                model.LineOne          = updateRequestModel.LineOne;
                model.LineTwo          = updateRequestModel.LineTwo;
                model.City             = updateRequestModel.City;
                model.StateProvince.Id = updateRequestModel.StateId;
                model.PostalCode       = updateRequestModel.PostalCode;
            }
                );

            mock.Setup(m => m.Delete(It.IsAny <int>())).Callback(
                (int id) =>
            {
                Address address = addressList.Where(m => m.Id == id).Single();
                addressList.Remove(address);
            });

            mock.Setup(m => m.Get(It.IsAny <int>(), It.IsAny <int>())).Returns(
                (int pageIndex, int pageSize) =>
            {
                List <Address> addressesList = new List <Address>();
                int count = (pageIndex) * pageSize;

                for (int i = count; i < addressList.Count; i++)
                {
                    if (i < count + pageSize)
                    {
                        addressesList.Add(addressList[i]);
                    }
                    else
                    {
                        break;
                    }
                }
                Paged <Address> paged = new Paged <Address>(addressesList, pageIndex, pageSize, addressList.Count);
                return(paged);
            });

            mock.Setup(m => m.GetByUserId(It.IsAny <int>())).Returns((int userId) =>
            {
                Address model = addressList.Where(m => m.UserId == userId).FirstOrDefault();

                Address newModel = null;
                if (model != null)
                {
                    newModel = new Address();
                    newModel.StateProvince = new StateProvince();

                    newModel.Id               = model.Id;
                    newModel.LineOne          = model.LineOne;
                    newModel.LineTwo          = model.LineTwo;
                    newModel.City             = model.City;
                    newModel.StateProvince.Id = model.StateProvince.Id;
                    newModel.PostalCode       = model.PostalCode;
                    newModel.UserId           = model.UserId;
                }
                return(newModel);
            });

            _addressService = mock.Object;
        }
        /// <summary>
        /// Update the account holder's current address
        /// </summary>
        /// <param name="body">Required parameter: Update account holder's current address</param>
        /// <return>Returns the void response from the API call</return>
        public void UpdateCurrentAddress(AddressUpdateRequest body)
        {
            var t = UpdateCurrentAddressAsync(body);

            APIHelper.RunTaskSynchronously(t);
        }