示例#1
0
        public virtual ActionResult Edit(MyAccountEditViewModel viewModel)
        {
            if (!ModelState.IsValid)
                return View(viewModel);

            using (var trans = new TransactionScope())
            {
                using (var context = new TTTEntities())
                {
                    var access = context.tblaccesses.Single(a => a.ID == viewModel.AccessID);                    

                    access.Email = viewModel.Email; //TODO: Validation on existing email

                    if (!string.IsNullOrEmpty(viewModel.Password) && !viewModel.IsFBLogin)
                        access.Password = Util.GetMD5Hash(viewModel.Password);
                    access.FirstName = viewModel.FirstName;
                    access.LastName = viewModel.LastName;
                    access.BirthDateDay = viewModel.BirthDateDay;
                    access.BirthDateMonth = viewModel.BirthDateMonth;
                    access.BirthDateYear = viewModel.BirthDateYear;
                    access.Gender = viewModel.Gender.HasValue ? viewModel.Gender.Value.ToString() : null;
                    access.Phone = viewModel.Phone;

                    context.SaveChanges();

                    Util.SessionAccess = access;

                    EditAddresses(viewModel, context);

                    context.SaveChanges();
                }

                trans.Complete();
            }

            return RedirectToAction(MVC.MyAccount.Index());
        }
示例#2
0
        private void EditAddresses(MyAccountEditViewModel viewModel, TTTEntities context)
        {
            var primaryAddress =
                context.tbladdresses
                    .SingleOrDefault(a => a.Active && a.IsPrimary && a.AccessID == viewModel.AccessID);
            var secondaryAddress =
                context.tbladdresses
                    .FirstOrDefault(a => a.Active && !a.IsPrimary && a.AccessID == viewModel.AccessID);

            primaryAddress = ConstructEditAddress(primaryAddress, viewModel.PrimaryAddress);
            secondaryAddress = ConstructEditAddress(secondaryAddress, viewModel.SecondaryAddress);

            if (viewModel.BillingFlag == 1)
            {
                primaryAddress.IsBilling = true;
                secondaryAddress.IsBilling = false;
            }
            else if (viewModel.BillingFlag == 2)
            {
                primaryAddress.IsBilling = false;
                secondaryAddress.IsBilling = true;
            }
            else
            {
                primaryAddress.IsBilling = false;
                secondaryAddress.IsBilling = false;
            }

            if (viewModel.ShippingFlag == 1)
            {
                primaryAddress.IsShipping = true;
                secondaryAddress.IsShipping = false;
            }
            else if (viewModel.ShippingFlag == 2)
            {
                primaryAddress.IsShipping = false;
                secondaryAddress.IsShipping = true;
            }
            else
            {
                primaryAddress.IsShipping = false;
                secondaryAddress.IsShipping = false;
            }

            if (ValidNewAddress(primaryAddress))
                context.tbladdresses.Add(primaryAddress);

            if (ValidNewAddress(secondaryAddress))
                context.tbladdresses.Add(secondaryAddress);

            var access = Util.SessionAccess;
            var salesOrder = context.trnsalesorders
                .Include(a => a.refstatu)
                .FirstOrDefault(a => a.Email == access.Email && a.refstatu.Name == "Open");
            if (salesOrder != null)
            {
                var soAddresses = context.lnksoaddresses.Where(a => a.SalesOrderID == salesOrder.ID && a.Active).ToList();
                foreach (var address in soAddresses)
                {
                    var addressType = (CheckoutAddressType)address.ChooseAddress;

                    switch (addressType)
                    {
                        case CheckoutAddressType.Primary:
                            BindToSalesOrderAddress(address, primaryAddress);
                            break;
                        case CheckoutAddressType.Secondary:
                            BindToSalesOrderAddress(address, secondaryAddress);
                            break;

                        default:
                            break;
                    }
                }
            }
        }
示例#3
0
        public virtual ActionResult Edit()
        {
            var accessID = Util.SessionAccess.ID;

            using (var context = new TTTEntities())
            {
                var access = context.tblaccesses.Single(a => a.ID == accessID);
                var primaryAddress = context.tbladdresses.SingleOrDefault(a => a.Active && a.IsPrimary && a.AccessID == accessID);
                var secondaryAddress = context.tbladdresses.FirstOrDefault(a => a.Active && !a.IsPrimary && a.AccessID == accessID);

                var viewModel = new MyAccountEditViewModel
                {
                    AccessID = access.ID,
                    Email = access.Email,
                    FirstName = access.FirstName,
                    LastName = access.LastName,
                    Phone = access.Phone,
                    Gender = string.IsNullOrEmpty(access.Gender) ? null : (Gender?)Util.ParseEnum<Gender>(access.Gender),
                    BirthDateDay = access.BirthDateDay,
                    BirthDateMonth = access.BirthDateMonth,
                    BirthDateYear = access.BirthDateYear,
                    //Password = access.Password,
                    //ConfirmPassword = access.Password,
                    IsFBLogin = !string.IsNullOrEmpty(access.FacebookID)
                };

                if (primaryAddress != null)
                {
                    viewModel.PrimaryAddress = ConvertToMyAccountAddress(primaryAddress);
                    viewModel.BillingFlag = primaryAddress.IsBilling ? 1 : viewModel.BillingFlag;
                    viewModel.ShippingFlag = primaryAddress.IsShipping ? 1 : viewModel.ShippingFlag;

                    if (!string.IsNullOrEmpty(primaryAddress.AddressLine1)
                        && !string.IsNullOrEmpty(primaryAddress.AddressLine2)
                        && !string.IsNullOrEmpty(primaryAddress.CityTown)
                        && !string.IsNullOrEmpty(primaryAddress.Postcode)
                        && !string.IsNullOrEmpty(primaryAddress.State))
                    {
                        viewModel.EnableHomeFlag = true;
                    }
                }

                if (secondaryAddress != null)
                {
                    viewModel.SecondaryAddress = ConvertToMyAccountAddress(secondaryAddress);
                    viewModel.BillingFlag = secondaryAddress.IsBilling ? 2 : viewModel.BillingFlag;
                    viewModel.ShippingFlag = secondaryAddress.IsShipping ? 2 : viewModel.ShippingFlag;

                    if (!string.IsNullOrEmpty(secondaryAddress.AddressLine1)
                        && !string.IsNullOrEmpty(secondaryAddress.AddressLine2)
                        && !string.IsNullOrEmpty(secondaryAddress.CityTown)
                        && !string.IsNullOrEmpty(secondaryAddress.Postcode)
                        && !string.IsNullOrEmpty(secondaryAddress.State))
                    {
                        viewModel.EnableWorkFlag = true;
                    }
                }

                var defaultCountryID = Util.GetDefaultCountryID(); ;
                if (!viewModel.PrimaryAddress.CountryID.HasValue || viewModel.PrimaryAddress.CountryID == 0)
                    viewModel.PrimaryAddress.CountryID = defaultCountryID;

                if (!viewModel.SecondaryAddress.CountryID.HasValue || viewModel.SecondaryAddress.CountryID == 0)
                    viewModel.SecondaryAddress.CountryID = defaultCountryID;

                return View(viewModel);
            }
        }