public ActionResult AccountDetails()
        {
            if (Session["USERINFO"] == null)
            {
                return RedirectToAction("LogOn");
            }

            var objUserModel = (UserModel) Session["USERINFO"];

            var objAccountSettingModel = new AccountSettingsViewModel
                                             {
                                                 UserName = objUserModel.UserName,
                                                 FirstName = objUserModel.FirstName,
                                                 LastName = objUserModel.LastName,
                                                 Address = objUserModel.Address,
                                                 Address2 = objUserModel.Address2,
                                                 City = objUserModel.City,
                                                 State = objUserModel.State,
                                                 Zip = objUserModel.Zip,
                                                 Country = objUserModel.Country,
                                                 Email = objUserModel.Email,
                                                 DayPhone = objUserModel.DayPhone,
                                                 Evening = objUserModel.Evening,
                                                 ShipToName = objUserModel.ShipToName,
                                                 ShipAddress = objUserModel.ShipAddress,
                                                 ShipAddress2 = objUserModel.ShipAddress2,
                                                 ShipCity = objUserModel.ShipCity,
                                                 ShipState = objUserModel.ShipState,
                                                 ShipZip = objUserModel.ShipZip,
                                                 ShipCountry = objUserModel.ShipCountry,
                                                 ShipInstruc = objUserModel.ShipInstruc,
                                                 IsEmailOptIn = objUserModel.EmailOptIn == "Y"
                                             };

            return View(objAccountSettingModel);
        }
        public ActionResult AccountDetails(AccountSettingsViewModel model)
        {
            var emailoptin =model.IsEmailOptIn?"Y":"N";
            //They are not used in this context but don't remove them they are do make model valid

            ModelState.Remove("Password");
            model.Password = "******";
            model.Password = "******";
            model.ConfirmPassword = "******";
            if (ModelState.IsValid)
             {
                 //Update the user details
                 var objUserModel = AccountSettingsService.UpdateUser(StoreNumber, model.UserName,
                                                                      model.FirstName, model.LastName, model.Address,
                                                                      model.Address2,
                                                                      model.City, model.State, model.Zip, model.Country,
                                                                      model.Email, model.DayPhone, model.Evening??"",
                                                                      model.ShipToName,
                                                                      model.ShipAddress, model.ShipAddress2,
                                                                      model.ShipCity,
                                                                      model.ShipState, model.ShipZip, model.ShipCountry,
                                                                      model.ShipInstruc, emailoptin,"", UvUsername,
                                                                      UvPassword, DbType, UvAddress, UvAccount,
                                                                      CacheTime, CacheTime,
                                                                      Strd3PortNumber, UseEncryption, Strd3PortNumber);

                 if (!string.IsNullOrEmpty(objUserModel.ErrorMsg))
                 {
                     ModelState.AddModelError("", objUserModel.ErrorMsg);
                 }
                 else
                 {
                     Session["USERINFO"] = objUserModel;

                     return RedirectToAction("MyAccount");
                 }
             }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult CreateNewUser(AccountSettingsViewModel model)
        {
            var emailoptin = Convert.ToBoolean(model.IsEmailOptIn) ? "Y" : "N";

            if (ModelState.IsValid)
            {
                var objUserModel = AccountSettingsService.AddUser(
                    StoreNumber ?? "",
                    model.UserName ?? "",
                    model.Password ?? "",
                    model.FirstName ?? "",
                    model.LastName ?? "",
                    model.Address ?? "",
                    model.Address2 ?? "",
                    model.City ?? "",
                    model.State ?? "",
                    model.Zip ?? "",
                    model.Country ?? "",
                    model.Email ?? "",
                    model.DayPhone ?? "",
                    model.Evening ?? "",
                    model.ShipToName ?? "",
                    model.ShipAddress ?? "",
                    model.ShipAddress2 ?? "",
                    model.ShipCity ?? "",
                    model.ShipState ?? "",
                    model.ShipZip ?? "",
                    model.ShipCountry ?? "",
                    model.ShipInstruc ?? "",
                    emailoptin ?? "",
                    UvUsername,
                    UvPassword,
                    DbType,
                    UvAddress,
                    UvAccount,
                    CacheTime,
                    CacheTime,
                    Strd3PortNumber,
                    UseEncryption,
                    Strd3PortNumber
                );

                if (!string.IsNullOrEmpty(objUserModel.ErrorMsg))
                {
                     ModelState.AddModelError("", objUserModel.ErrorMsg);
                }
                else
                {
                    Session["USERINFO"] = objUserModel;

                    Session["ACCTYPE"] = objUserModel.Type;

                    return RedirectToAction("MyAccount");
                }

            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        /// <summary>
        /// Get the detail of customer
        /// </summary>
        /// <returns></returns>
        public ActionResult JsonGetCustomerDetail()
        {
            try
            {
                //Get the variable from the querystring
                var customerId = Request["CustomerId"] ?? "";

                if (customerId.Length > 1)
                {

                    var customerDetail = CustomerService.GetCustomerDetailById(StoreNumber, customerId, UvUsername,
                                                                                 UvPassword,
                                                                                 DbType, UvAddress, UvAccount, CacheTime,
                                                                                 CacheTime,
                                                                                 Strd3PortNumber, UseEncryption, Strd3PortNumber);

                    var customerDetailViewModel = new AccountSettingsViewModel
                    {
                        Address = customerDetail.Address,
                        Address2 = customerDetail.Address2,
                        City = customerDetail.City,
                        Country = customerDetail.Country,
                        DayPhone = customerDetail.DayPhone,
                        Email = customerDetail.Email,
                        FirstName = customerDetail.FirstName,
                        LastName = customerDetail.LastName,
                        ShipAddress = customerDetail.ShipAddress,
                        ShipAddress2 = customerDetail.ShipAddress2,
                        ShipCity = customerDetail.ShipCity,
                        ShipCountry = customerDetail.ShipCountry,
                        ShipInstruc = customerDetail.ShipInstruc,
                        ShipState = customerDetail.ShipState,
                        ShipToName = customerDetail.ShipToName,
                        ShipZip = customerDetail.ShipZip,
                        State = customerDetail.State,
                        UserName = customerDetail.UserName,
                        Zip = customerDetail.Zip,
                        IsEmailOptIn = customerDetail.EmailOptIn.Equals("Y"),
                        DropDownAccountType = customerDetail.TypeDescrition ?? ""
                    };

                    ViewBag.AccountType = customerDetail.TypeDescrition ?? "";
                    ViewBag.State = customerDetail.State ?? "";

                    //Get the history of te order for the customers
                    var orderModels = OrderService.GetOrderHistory(StoreNumber, customerId, UvUsername,
                                                                     UvPassword,
                                                                     DbType, UvAddress, UvAccount, CacheTime,
                                                                     CacheTime,
                                                                     Strd3PortNumber, UseEncryption, Strd3PortNumber);
                    IEnumerable<OrderViewModel> orderViewModels;

                    orderViewModels = (from order in orderModels
                                       select new OrderViewModel
                                       {
                                           OrderId = order.OrderId,
                                           ConfNumber = order.ConfNumber,
                                           DatePlaced = order.DatePlaced,
                                           DateProcessed = order.DateProcessed,
                                           Status = order.Status,
                                           Amount = order.Amount
                                       });

                    var customerViewModels = new CustomerDetailViewModel
                    {
                        CustomerDetail = customerDetailViewModel,
                        AllAccountType = customerDetail.AllAccountType,
                        OrderViewModels = orderViewModels

                    };

                    //Put the value to the session
                    Session["MAINTUSERINFO"] = customerViewModels;

                    return PartialView("EditorTemplates/Admin/customerDetail", customerViewModels);
                }

                return Json("Please enter atleast two charactors");
            }
            catch (Exception x)
            {
                return Json(x.Message);
            }
        }