예제 #1
0
        public ActionResult Address(Address address)
        {
            ValidateAddress(address);

            if (ModelState.IsValid) {

                //save the address
                address.AddressID = _customerRepository.SaveAddress(address);
                this.CurrentCart.ShippingAddress = address;

                //calc the tax
                this.CurrentCart.TaxAmount = this.CalculateTax(this.CurrentCart);
                this.CurrentCart.BillingAddress = address;

                //set the shipping methods
                this.ShippingMethods = this.GetShippingMethods(this.CurrentCart);

                //default to the first
                this.CurrentCart.ShippingService = this.ShippingMethods[0].ServiceName;
                this.CurrentCart.ShippingAmount = this.ShippingMethods[0].Cost;
                this.CurrentCart.ShippingMethodID = this.ShippingMethods[0].ID;

                //save the cart
                this.SaveCart();

                //send to billing
                return RedirectToAction("Finalize");
            } else {
                //let error handling pick it up
                return View();
            }
        }
예제 #2
0
        DbCommand GetAddressCommand(Address address)
        {
            var sql = new SqlStatement(connectionStringName);

            var settings = new Dictionary<string, object>()
                {
                    {AddressesTable.Columns.UserName, address.UserName},
                    {AddressesTable.Columns.FirstName, address.FirstName},
                    {AddressesTable.Columns.LastName, address.LastName},
                    {AddressesTable.Columns.Email, address.Email},
                    {AddressesTable.Columns.Street1, address.Street1},
                    {AddressesTable.Columns.Street2, address.Street2 != null ? address.Street2 : ""},
                    {AddressesTable.Columns.City, address.City},
                    {AddressesTable.Columns.StateOrProvince, address.StateOrProvince},
                    {AddressesTable.Columns.Zip, address.Zip},
                    {AddressesTable.Columns.Country, address.Country},
                    {AddressesTable.Columns.IsDefault, address.IsDefault}
               };

            if (SqlHelper.RecordExists(connectionStringName,AddressesTable.TABLE_NAME, new Dictionary<string, object>()
                {
                    {AddressesTable.Columns.UserName,address.UserName},
                    {AddressesTable.Columns.Street1,address.Street1},
                    {AddressesTable.Columns.City,address.City},
                    {AddressesTable.Columns.StateOrProvince,address.StateOrProvince},
                }))
            {
                //update
                sql = AddressesTable.Update(settings)
                    .Where(AddressesTable.Columns.UserName, address.UserName)
                    .And(AddressesTable.Columns.Street1, address.Street1)
                    .And(AddressesTable.Columns.City, address.City)
                    .And(AddressesTable.Columns.StateOrProvince, address.StateOrProvince);

            } else {
                //insert
                sql = AddressesTable.Insert(settings);

            }
            var cmd = sql.BuildCommand();

            //add the params
            return cmd;
        }
예제 #3
0
        internal Address LoadAddress(DbDataReader rdr)
        {
            var result=new Address(
                AddressesTable.ReadUserName(rdr),
                AddressesTable.ReadFirstName(rdr),
                AddressesTable.ReadLastName(rdr),
                AddressesTable.ReadEmail(rdr),
                AddressesTable.ReadStreet1(rdr),
                AddressesTable.ReadStreet2(rdr),
                AddressesTable.ReadCity(rdr),
                AddressesTable.ReadStateOrProvince(rdr),
                AddressesTable.ReadZip(rdr),
                AddressesTable.ReadCountry(rdr));

            result.AddressID = AddressesTable.ReadAddressID(rdr);
            return result;
        }
예제 #4
0
        public int SaveAddress(Address address)
        {
            GetAddressCommand(address).ExecuteNonQuery();

            var sql = string.Format("SELECT MAX({0}) FROM {1} WHERE {2} = @p0",
                AddressesTable.ColumnsQualified.AddressID,
                AddressesTable.TABLE_NAME,
                AddressesTable.ColumnsQualified.UserName);
            var cmd = new SqlStatement(connectionStringName).Add(sql).BuildCommand();
            cmd.AddParameter("@p0", address.UserName);
            object id = cmd.ExecuteScalar();
            return (int)id;
        }
예제 #5
0
 private void ValidateAddress(Address address)
 {
     // Validation logic
     if (String.IsNullOrEmpty(address.FirstName))
         ModelState.AddModelError("FirstName", "First name is required.");
     if (String.IsNullOrEmpty(address.LastName))
         ModelState.AddModelError("LastName", "Last name is required.");
     if (String.IsNullOrEmpty(address.Email))
         ModelState.AddModelError("Email", "E-mail name is required.");
     if (String.IsNullOrEmpty(address.Street1))
         ModelState.AddModelError("Street1", "Street is required.");
     if (String.IsNullOrEmpty(address.City))
         ModelState.AddModelError("City", "City is required.");
     if (String.IsNullOrEmpty(address.StateOrProvince))
         ModelState.AddModelError("StateOrProvince", "State or province is required.");
     if (String.IsNullOrEmpty(address.Zip))
         ModelState.AddModelError("Zip", "Zip code is required.");
     if (String.IsNullOrEmpty(address.Country))
         ModelState.AddModelError("Country", "Country is required.");
 }