Esempio n. 1
0
        private CheckoutAddress ConstructMyAccountAddress(tbladdress address)
        {
            var result = new CheckoutAddress
            {
                AddressLine1 = address.AddressLine1,
                AddressLine2 = address.AddressLine2,
                CityTown = address.CityTown,
                CountryID = address.CountryID.HasValue ? address.CountryID.Value : 0,
                Postcode = address.Postcode,
                State = address.State
            };

            return result;
        }
Esempio n. 2
0
 private void BindToSalesOrderAddress(lnksoaddress soAddress, tbladdress address)
 {
     soAddress.AddressLine1 = address.AddressLine1;
     soAddress.AddressLine2 = address.AddressLine2;
     soAddress.CityTown = address.CityTown;
     soAddress.CountryID = address.CountryID;
     soAddress.Postcode = address.Postcode;
     soAddress.State = address.State;
 }
Esempio n. 3
0
        private bool ValidNewAddress(tbladdress address)
        {
            var valid = false;

            valid = 
                address.ID == 0
                && !string.IsNullOrEmpty(address.AddressLine1)
                && !string.IsNullOrEmpty(address.AddressLine2)
                && !string.IsNullOrEmpty(address.CityTown)
                && !string.IsNullOrEmpty(address.Postcode)
                && !string.IsNullOrEmpty(address.State);

            return valid;
        }
Esempio n. 4
0
        private tbladdress ConstructEditAddress(tbladdress address, MyAccountAddress modelAddress)
        {
            if (address == null)
            {
                address = new tbladdress
                {
                    AccessID = Util.SessionAccess.ID,
                    Active = true,
                    CreateDT = DateTime.Now
                };
            }
            else
            {
                address.UpdateDT = DateTime.Now;
            }

            address.AddressLine1 = modelAddress.AddressLine1;
            address.AddressLine2 = modelAddress.AddressLine2;
            address.CityTown = modelAddress.CityTown;
            address.CountryID = modelAddress.CountryID;
            address.Postcode = modelAddress.Postcode;
            address.State = modelAddress.State;
            address.IsPrimary = modelAddress.IsPrimary;

            return address;
        }
Esempio n. 5
0
        private MyAccountAddress ConvertToMyAccountAddress(tbladdress address)
        {
            var myAccountAddress = new MyAccountAddress
            {
                ID = address.ID,
                AddressLine1 = address.AddressLine1,
                AddressLine2 = address.AddressLine2,
                CityTown = address.CityTown,
                CountryID = address.CountryID,
                IsPrimary = address.IsPrimary,
                Postcode = address.Postcode,
                State = address.State
            };

            return myAccountAddress;
        }
Esempio n. 6
0
        public virtual ActionResult Shipping(CheckoutShippingViewModel viewModel)
        {
            var access = Util.SessionAccess;

            using (var context = new TTTEntities())
            {
                if (viewModel.SalesOrderAddressID == 0)
                {
                    var salesOrderID = context.trnsalesorders
                        .Include(a => a.refstatu)
                        .Single(a => a.Email == access.Email && a.refstatu.Name == "Open")
                        .ID;

                    var oldAddress = context.lnksoaddresses
                        .Where(a => a.Active && a.IsShipping && a.SalesOrderID == salesOrderID).ToList();
                    oldAddress.ForEach(a => { a.Active = false; a.UpdateDT = DateTime.Now; });

                    context.lnksoaddresses.Add(new lnksoaddress
                    {
                        Active = true,
                        AddressLine1 = viewModel.Address.AddressLine1,
                        AddressLine2 = viewModel.Address.AddressLine2,
                        CityTown = viewModel.Address.CityTown,
                        CountryID = viewModel.Address.CountryID,
                        CreateDT = DateTime.Now,
                        FirstName = viewModel.FirstName,
                        IsShipping = true,
                        LastName = viewModel.LastName,
                        Postcode = viewModel.Address.Postcode,
                        SalesOrderID = salesOrderID,
                        State = viewModel.Address.State,
                        ChooseAddress = viewModel.AddressTypeID,
                        Phone = viewModel.Phone
                    });
                }
                else
                {
                    var salesOrderShippingAddress = context.lnksoaddresses.Single(a => a.ID == viewModel.SalesOrderAddressID);
                    salesOrderShippingAddress.AddressLine1 = viewModel.Address.AddressLine1;
                    salesOrderShippingAddress.AddressLine2 = viewModel.Address.AddressLine2;
                    salesOrderShippingAddress.CityTown = viewModel.Address.CityTown;
                    salesOrderShippingAddress.CountryID = viewModel.Address.CountryID;
                    salesOrderShippingAddress.UpdateDT = DateTime.Now;
                    salesOrderShippingAddress.FirstName = viewModel.FirstName;
                    salesOrderShippingAddress.IsShipping = true;
                    salesOrderShippingAddress.LastName = viewModel.LastName;
                    salesOrderShippingAddress.ChooseAddress = viewModel.AddressTypeID;
                    salesOrderShippingAddress.Postcode = viewModel.Address.Postcode;
                    salesOrderShippingAddress.State = viewModel.Address.State;
                    salesOrderShippingAddress.Phone = viewModel.Phone;
                }

                var addressType = (CheckoutAddressType)viewModel.AddressTypeID;
                if (addressType != CheckoutAddressType.Others)
                {
                    var isPrimary = addressType == CheckoutAddressType.Primary;
                    var accountAddress = context.tbladdresses
                        .FirstOrDefault(a => a.IsPrimary == isPrimary && a.Active && a.AccessID == access.ID);
                    var shippingExist = context.tbladdresses
                        .Any(a => a.Active && a.AccessID == access.ID && a.IsShipping && a.IsPrimary != isPrimary);
                    var isShipping = shippingExist ? false : true;

                    if (accountAddress == null)
                    {
                        accountAddress = new tbladdress
                        {
                            AccessID = access.ID,
                            Active = true,
                            AddressLine1 = viewModel.Address.AddressLine1,
                            AddressLine2 = viewModel.Address.AddressLine2,
                            CityTown = viewModel.Address.CityTown,
                            CountryID = viewModel.Address.CountryID,
                            CreateDT = DateTime.Now,
                            IsShipping = isShipping,
                            IsPrimary = isPrimary,
                            Postcode = viewModel.Address.Postcode,
                            State = viewModel.Address.State
                        };
                        context.tbladdresses.Add(accountAddress);
                    }
                    else
                    {
                        accountAddress.IsShipping = isShipping;
                    }
                }

                context.SaveChanges();
            }

            return RedirectToAction(MVC.Checkout.Summary());
        }