public ActionResult OpenContent(int pageId)
        {
            helperOpenContent helperItem = new helperOpenContent();
            pageShared ps = new pageShared(db);

            var item = db.tbl_page.Include("tbl_category").Where(a => a.pageId == pageId).FirstOrDefault();

            helperItem.pageTitle = item.name;

            if (!string.IsNullOrWhiteSpace(item.title))
            {
                helperItem.pageTitle = item.title;
            }

            var parentCategoryList = db.tbl_category.Include("tbl_page").Where(a => a.parentId == item.tbl_category.parentId && a.statu).ToList();
            var selectedUrl = ps.getPageUrl(item);

            helperItem.leftMenuList = getStaticLeftMenu(parentCategoryList, pageId);

            helperItem.breadCrumbItem = getBreadCrumbStaticPage(item.name);

            helperItem.list = db.tbl_openContent.Where(a => a.langId == langId && a.categoryId == item.categoryId && a.statu).OrderBy(a => a.sequence).Select(a => new openContentItem() { title = a.title, detail = a.detail }).ToList();

            //Title
            ps.pageTitleBind(item, helperItem, langId);

            return View(helperItem);
        }
        public ActionResult Index(int pageId)
        {
            helperStaticPage helperItem = new helperStaticPage();
            pageShared ps = new pageShared(db);

            var item = db.tbl_page.Include("tbl_category").Where(a => a.pageId == pageId).FirstOrDefault();

            if (item.tbl_category == null)
            {
                return null;
            }

            var parentCategoryList = db.tbl_category.Include("tbl_page").Where(a => a.parentId == item.tbl_category.parentId).ToList();
            var selectedUrl = ps.getPageUrl(item);

            helperItem.leftMenuList = getStaticLeftMenu(parentCategoryList, pageId);
            helperItem.breadCrumbItem = getBreadCrumbStaticPage(item.name);
            helperItem.pageTitle = item.name;

            if (!string.IsNullOrWhiteSpace(item.title))
            {
                helperItem.pageTitle = item.title;
            }

            helperItem.detail = item.detail;

            //Title
            ps.pageTitleBind(item, helperItem, langId);

            return View(helperItem);
        }
        public ActionResult ActivationResent(int pageId)
        {
            helperActivationResent helperPage = new helperActivationResent();
            pageShared ps = new pageShared(db);

            var pageItem = ps.getPageById(pageId);

            if (pageItem == null)
            {
                return null;
            }

            ps.pageTitleBind(pageItem, helperPage, langId);
            helperPage.setTitle(pageItem.name);
            helperPage.breadCrumbItem = getBreadCrumbStaticPage(pageItem.name);

            return View(helperPage);
        }
        public ActionResult Index(int pageId)
        {
            helperAllBrand helperItem = new helperAllBrand();

            // Brand List
            pageShared ps = new pageShared(db);
            var productList = ps.getPageByType(pageType.productList ,langId);
            helperItem.brandList = getBrandList(productList.url);

            // All BranName
            pageShared pc = new pageShared(db);
            var brandPageItem = pc.getPageById(pageId);
            helperItem.brandName = brandPageItem.name;
            helperItem.breadCrumbItem = getBreadCrumbAllBrand(brandPageItem.name);

            // Title
            pc.pageTitleBind(brandPageItem, helperItem, langId);

            return View(helperItem);
        }
        public ActionResult ChangePassword(int pageId, helperChangePassword pageHelper)
        {
            pageShared ps = new pageShared(db);
            userShared us = new userShared(db);
            addressShared ash = new addressShared(db);

            var pageItem = ps.getPageById(pageId);
            var mainAccountPage = db.tbl_page.Include("tbl_category").Where(a => a.pageTypeId == (int)pageType.account).FirstOrDefault();

            ps.pageTitleBind(pageItem, pageHelper, langId);
            pageHelper.setTitle(pageItem.name);
            pageHelper.detail = pageItem.detail;
            pageHelper.leftMenuList = generateLeftMenu(mainAccountPage, pageItem.url);
            pageHelper.breadCrumbItem = getBreadCrumbTwoPage(mainAccountPage.name, mainAccountPage.url, pageItem.name, pageItem.url);
            pageHelper.cancelUrl = langCode + "/" + mainAccountPage.url + ".html";

            if (pageHelper.password != pageHelper.passwordRep)
            {
                ModelState.AddModelError("passwordRep", lang.formPassworRepSame);
            }

            if (ModelState.IsValid)
            {
                topCart cartItem = (topCart)ViewData["topCart"];

                try
                {
                    us.updateUserPassword(cartItem.userId, MD5(pageHelper.password));
                    pageHelper.message = getSuccesMessage(lang.updatePasswordSuccess, "autoHide");
                    pageHelper.isMessageExist = true;

                }
                catch (Exception ex)
                {
                    errorSend(ex, "Account Password Update", true);
                }
            }
            else
            {
                string messages = string.Join("<br /> ", ModelState.Values
                                        .SelectMany(x => x.Errors)
                                        .Select(x => x.ErrorMessage));

                pageHelper.message = getErrorMessage(messages, "autoHide");
                pageHelper.isMessageExist = true;
            }

            return View(pageHelper);
        }
        public ActionResult AddressIndex(int pageId)
        {
            pageShared ps = new pageShared(db);
            userShared us = new userShared(db);
            addressShared ash = new addressShared(db);

            var pageItem = ps.getPageById(pageId);
            var mainAccountPage = db.tbl_page.Include("tbl_category").Where(a => a.pageTypeId == (int)pageType.account).FirstOrDefault();

            helperAddress pageHelper = new helperAddress();

            ps.pageTitleBind(pageItem, pageHelper, langId);
            pageHelper.setTitle(pageItem.name);
            pageHelper.detail = pageItem.detail;

            pageHelper.leftMenuList = generateLeftMenu(mainAccountPage, pageItem.url);
            pageHelper.breadCrumbItem = getBreadCrumbTwoPage(mainAccountPage.name, mainAccountPage.url, pageItem.name, pageItem.url);

            topCart cartItem = (topCart)ViewData["topCart"];
            var userItem = us.getUserById(cartItem.userId);

            pageHelper.userguid = userItem.guid;
            pageHelper.addressList = ash.getAddressListTemplate(userItem.userId);

            return View(pageHelper);
        }
        public ActionResult ResetPassword(int pageId, string resetcode)
        {
            helperResetPassword helperPage = new helperResetPassword();
            pageShared ps = new pageShared(db);

            var pageItem = ps.getPageById(pageId);

            if (pageItem == null)
            {
                return null;
            }

            ps.pageTitleBind(pageItem, helperPage, langId);
            helperPage.setTitle(pageItem.name);
            helperPage.breadCrumbItem = getBreadCrumbStaticPage(pageItem.name);

            helperPage.detail = pageItem.detail;

            bool isErrorExist = false;

            if (string.IsNullOrWhiteSpace(resetcode))
            {

                helperPage.message = App_GlobalResources.lang.resetPasswordNull;
                isErrorExist = true;
            }
            else
            {
                var forgetPasswordItem = db.tbl_forgetPassword.Where(a => a.code == resetcode).FirstOrDefault();

                if (forgetPasswordItem != null)
                {
                    helperPage.resetCode = forgetPasswordItem.code;
                    helperPage.userId = forgetPasswordItem.userId;
                    return View(helperPage);

                }
                else
                {
                    helperPage.message = App_GlobalResources.lang.resetPasswordWrong;
                    isErrorExist = true;
                }

            }

            if (isErrorExist)
            {
                string forgetPasswordLink = "";
                var forgetPassPage = ps.getPageByType(pageType.forgetPassword, langId);

                if (forgetPassPage != null)
                {
                    forgetPasswordLink = getSiteName(Request) + langCode + "/" + forgetPassPage.url + ".html";
                }

                helperPage.message = helperPage.message.Replace("[forgetPasswordLink]", forgetPasswordLink);
                helperPage.isMessageExist = true;
                helperPage.isErrorExist = true;

                return View(helperPage);
            }

            return null;
        }
        public ActionResult UserInfo(int pageId)
        {
            pageShared ps = new pageShared(db);
            userShared us = new userShared(db);
            addressShared ash = new addressShared(db);

            var pageItem = ps.getPageById(pageId);
            var mainAccountPage = db.tbl_page.Include("tbl_category").Where(a => a.pageTypeId == (int)pageType.account).FirstOrDefault();

            topCart cartItem = (topCart)ViewData["topCart"];

            helperUserInfo pageHelper = new helperUserInfo();

            ps.pageTitleBind(pageItem, pageHelper, langId);
            pageHelper.setTitle(pageItem.name);
            pageHelper.detail = pageItem.detail;

            pageHelper.leftMenuList = generateLeftMenu(mainAccountPage, pageItem.url);
            pageHelper.breadCrumbItem = getBreadCrumbTwoPage(mainAccountPage.name, mainAccountPage.url, pageItem.name, pageItem.url);

            var userItem = us.getUserById(cartItem.userId);

            pageHelper.name = userItem.name;
            pageHelper.surname = userItem.surname;
            pageHelper.email = userItem.email;

            if (userItem.birthday.HasValue)
            {
                var birthday = userItem.birthday.Value;

                pageHelper.day = birthday.Day;
                pageHelper.month = birthday.Month;
                pageHelper.year = birthday.Year;
            }

            if (userItem.gender.HasValue)
            {
                pageHelper.gender = userItem.gender.Value;
            }

            pageHelper.cancelUrl = langCode + "/" + mainAccountPage.url + ".html";

            return View(pageHelper);
        }
        public ActionResult OrderSearch(int pageId)
        {
            topCart cartItem = (topCart)ViewData["topCart"];
            pageShared ps = new pageShared(db);
            var pageMainAccount = db.tbl_page.Include("tbl_category").Where(a => a.pageTypeId == (int)pageType.account).FirstOrDefault();

            if (cartItem.isRegisteredUser)
            {

                var pageOrderList = ps.getPageByType(pageType.accountOrders, langId);
                return Redirect("~/" + langCode + "/" + pageMainAccount.url + "/" + pageOrderList.url + ".html");
            }

            var pageItem = db.tbl_page.Include("tbl_category").Where(a => a.pageId == pageId).FirstOrDefault();

            helperOrderSearch pageHelper = new helperOrderSearch();

            ps.pageTitleBind(pageItem, pageHelper, langId);
            pageHelper.detail = pageItem.detail;
            pageHelper.breadCrumbItem = getBreadCrumbStaticPage(pageItem.name);

            var parentCategoryList = db.tbl_category.Include("tbl_page").Where(a => a.parentId == pageItem.tbl_category.parentId && a.statu).ToList();
            pageHelper.leftMenuList = getStaticLeftMenu(parentCategoryList, pageId);

            return View(pageHelper);
        }
        public ActionResult OrderDetail(int pageId, string orderGuid)
        {
            orderShared os = new orderShared(db);
            addressShared ads = new addressShared(db);

            if (!string.IsNullOrWhiteSpace(orderGuid))
            {

                var orderItem = os.getOrderByGuid(orderGuid);

                if (orderItem != null)
                {
                    pageShared ps = new pageShared(db);
                    var pageItem = ps.getPageById(pageId);

                    var orderPage = ps.getPageByType(pageType.accountOrders, langId);

                    helperOrderDetail pageHelper = new helperOrderDetail();

                    ps.pageTitleBind(pageItem, pageHelper, langId);
                    pageHelper.setTitle(pageItem.name);
                    pageHelper.detail = pageItem.detail;

                    pageHelper.orderSummary = os.getOrderSummary(orderItem);

                    pageHelper.orderNo = orderItem.orderNo;
                    pageHelper.orderStatuHtml = os.getOrderStatuString(orderItem.orderStatu);

                    // On Cargo Add Track Url
                    if ((orderStatu)orderItem.orderStatu == orderStatu.onCargo && !string.IsNullOrWhiteSpace(orderItem.shipmentNo))
                    {
                        pageHelper.orderStatuHtml = pageHelper.orderStatuHtml + " " + os.getCargoTrackHtml(orderItem);
                    }

                    pageHelper.salesAgreement = orderItem.salesAgreement;
                    pageHelper.preSalesAgreement = orderItem.preSalesAgreement;

                    var deliveryAddressItem = ads.getAddressHtmlFromObj(orderItem.deliveryAddressId, orderItem.deliveryAddressObj);
                    var billingAddressItem = ads.getAddressHtmlFromObj(orderItem.billingAddressId, orderItem.billingAddressObj);

                    pageHelper.deliveryAddress = ads.getAddressHtml(deliveryAddressItem, AddressHtmlType.orderDetail, this);
                    pageHelper.billingAddress = ads.getAddressHtml(billingAddressItem, AddressHtmlType.orderDetail, this);

                    pageHelper.orderNote = orderItem.orderNote;

                    topCart cartItem = (topCart)ViewData["topCart"];

                    if (cartItem.isRegisteredUser)
                    {
                        pageHelper.isGoBackExist = true;

                        var mainAccountPage = ps.getPageByType(pageType.account, langId);
                        var orderListPage = ps.getPageByType(pageType.accountOrders, langId);

                        pageHelper.goBackLink = langCode + "/" + mainAccountPage.url + "/" + orderListPage.url + ".html";

                    }

                    return View(pageHelper);

                }
            }

            return null;
        }
        public ActionResult ActivationUpdate(int pageId, string activationCode)
        {
            helperActivationUpdate helperPage = new helperActivationUpdate();

            pageShared ps = new pageShared(db);

            var pageItem = ps.getPageById(pageId);

            if (pageItem == null)
            {
                return null;
            }

            ps.pageTitleBind(pageItem, helperPage, langId);
            helperPage.setTitle(pageItem.name);
            helperPage.breadCrumbItem = getBreadCrumbStaticPage(pageItem.name);

            var pageResentActivation = ps.getPageByType(pageType.activationResent, langId);

            string resendActivationLink = "";

            if (pageResentActivation != null)
            {
                resendActivationLink = Url.Content("~/") + langCode + "/" + pageResentActivation.url + ".html";
            }

            // activation boş
            if (string.IsNullOrWhiteSpace(activationCode))
            {
                helperPage.message = getErrorMessage(App_GlobalResources.lang.activationCodeError.Replace("[resendLink]", resendActivationLink));
            }

            var activationItem = db.tbl_activation.Where(a => a.code == activationCode).OrderByDescending(a => a.activationId).FirstOrDefault();

            // activation Null
            if (activationItem == null)
            {
                helperPage.message = getErrorMessage(App_GlobalResources.lang.activationCodeError.Replace("[resendLink]", resendActivationLink));
                return View(helperPage);
            }

            try
            {
                var userItem = db.tbl_user.Where(a => a.userId == activationItem.userId).FirstOrDefault();

                if (userItem != null)
                {
                    userItem.registerStatuId = (int)registerStatu.registered;
                    db.tbl_activation.Remove(activationItem);
                    db.SaveChanges();

                    helperPage.message = getSuccesMessage(App_GlobalResources.lang.activationCodeSucess);

                    // Set UserId, User Role , CheckoutProcess
                    setLoginSession(userItem);

                    // Guest Basket => User Basket
                    if (ViewData["topCart"] != null)
                    {
                        var cartItem = (topCart)ViewData["topCart"];
                        basketShared bs = new basketShared(db);

                        try
                        {
                            bs.updateUserCartFromGuestCode(userItem.userId, cartItem.guestGuid);
                        }
                        catch (Exception ex)
                        {
                            errorSend(ex, "Guest Sepeti , Usera aktarmada ");
                        }
                    }

                    // Thanks Mail
                    var settingItem = db.tbl_settings.Where(a => a.langId == langId).FirstOrDefault();
                    if (settingItem != null && settingItem.registerIsThankMessageSend)
                    {
                        mailShared ms = new mailShared(db, langId);
                        var mailContentItem = ms.getRegisterThankMailContent(userItem.name, userItem.surname);

                        try
                        {
                            mailSend(userItem.email, mailContentItem.Item1, mailContentItem.Item2);
                        }
                        catch (Exception ex)
                        {
                            errorSend(ex, "Thank Mail sent");

                        }
                    }

                }
                else  // activation var Fakat User ile Eşleşmiyor
                {
                    helperPage.message = getErrorMessage(App_GlobalResources.lang.activationCodeError.Replace("[resendLink]", resendActivationLink));
                }

            }
            catch (Exception ex)
            {
                errorSend(ex, "Activation Durumu update etmede", true);
            }

            return View(helperPage);
        }
        public ActionResult ResetPassword(int pageId, helperResetPassword helperPage)
        {
            pageShared ps = new pageShared(db);
            userShared us = new userShared(db);

            if (helperPage.password != helperPage.passwordRep)
            {
                ModelState.AddModelError("passwordRep", App_GlobalResources.lang.formPassworRepSame);
            }

            var pageItem = ps.getPageById(pageId);

            if (pageItem == null)
            {
                return null;
            }

            ps.pageTitleBind(pageItem, helperPage, langId);
            helperPage.setTitle(pageItem.name);
            helperPage.breadCrumbItem = getBreadCrumbStaticPage(pageItem.name);
            helperPage.detail = pageItem.detail;

            if (ModelState.IsValid)
            {
                // password - code reControl
                var forgetItem = db.tbl_forgetPassword.Where(a => a.code == helperPage.resetCode).FirstOrDefault();

                if (forgetItem == null || forgetItem.userId != helperPage.userId)
                {
                    helperPage.isErrorExist = true;
                    helperPage.isMessageExist = true;
                    helperPage.message = getErrorMessage(App_GlobalResources.lang.unexpectedErrorMsg);
                    return View(helperPage);
                }

                // Reset Password
                try
                {
                    us.updateUserPassword(helperPage.userId, MD5(helperPage.password));
                    helperPage.isMessageExist = true;
                    helperPage.message = getSuccesMessage(App_GlobalResources.lang.resetPasswordSuccess);

                    string loginUrl = "";

                    var loginPage = ps.getPageByType(pageType.registerLogin, langId);

                    if (loginPage != null)
                    {
                        loginUrl = getSiteName(Request) + langCode + "/" + loginPage.url + ".html";
                    }

                    helperPage.message = helperPage.message.Replace("[loginPage]", loginUrl);

                }
                catch (Exception ex)
                {
                    errorSend(ex, "updatePassword", true);

                    helperPage.isErrorExist = false;
                    helperPage.isMessageExist = true;
                    helperPage.message = getErrorMessage(App_GlobalResources.lang.unexpectedErrorMsg);
                }

                try
                {
                    us.deleteForgetPasswordByUserId(helperPage.userId);
                }
                catch (Exception ex)
                {
                    errorSend(ex, "ForgetPasswordDelete");
                }
            }

            return View(helperPage);
        }
        public ActionResult Index(int pageId)
        {
            if (Request.QueryString["keyWord"] == null)
            {
                return null;
            }

            string searchWord = Request.QueryString["keyWord"];

            helperSearch helperItem = new helperSearch();
            pageShared ps = new pageShared(db);
            productShared pc = new productShared(db);

            var searchPage = ps.getPageByType(pageType.search, langId);
            helperItem.searchLink = Url.Content("~/") + langCode + "/" + searchPage.url + ".html";

            var item = db.tbl_page.Include("tbl_category").Where(a => a.pageId == pageId).FirstOrDefault();

            if (item == null)
            {
                return null;
            }

            helperItem.breadCrumbItem = getBreadCrumbStaticPage(item.name);
            helperItem.setTitle(item.name);
            helperItem.detail = item.detail;

            //Title
            ps.pageTitleBind(item, helperItem, langId);

            //string pattern = getPatternBySearchWord(searchWord);
            helperItem.searchWord = searchWord;

            //helperItem.searchList = new List<searchResultItem>();
            helperItem.searchList = getSearchResultList(searchWord);

            if (helperItem.searchList.Count > 0)
            {
                helperItem.resultFound = string.Format(App_GlobalResources.lang.totalResultFound, helperItem.searchList.Count);
            }
            else
            {
                helperItem.resultFound = App_GlobalResources.lang.noResultFound;
            }

            int productCount = helperItem.searchList.Count;
            int currentPage = pc.getCurrentPage(Request, productCount, 10);
            helperItem.pagingItem = pc.getPageItem(productCount, currentPage, 10, "?keyWord=" + searchWord + "&sayfa=");
            helperItem.searchList = helperItem.searchList.Skip((currentPage - 1) * 10).Take(10).ToList();
            helperItem.searchKeyWordList = Newtonsoft.Json.JsonConvert.SerializeObject(getSearchKeywordList(searchWord));

            return View(helperItem);
        }
        public ActionResult Index(int pageId)
        {
            var helperPage = new helperProductList();

            // mainProductUrl
            pageShared ps = new pageShared(db);
            var item = ps.getPageById(pageId);

            helperPage.breadCrumbItem = getIndexBreadCrumbProductList(item.name);
            helperPage.header = item.name;

            var newProductList = db.tbl_product.Include("tbl_stock").Include("tbl_gallery").Include("tbl_carModelProduct.tbl_carModel.tbl_carBrand").Where(a => a.statu && a.isDeleted == false && a.tbl_stock.Any(b => b.stockCount > 0) && a.tbl_carModelProduct.Any(c => c.tbl_carModel != null) && a.tbl_carModelProduct.Any(c => c.tbl_carModel != null) && a.tbl_carModelProduct.Any(c => c.tbl_carModel.tbl_carBrand != null) && a.langId == langId).OrderByDescending(a => a.sequence).ToList();

            productShared pc = new productShared(db);

            int productCount = newProductList.Count;
            int currentPage = pc.getCurrentPage(Request, productCount, 6);
            helperPage.pagingItem = pc.getPageItem(productCount, currentPage, 6, "?sayfa=");

            helperPage.productList = pc.getProductSummary(item.url, newProductList.Skip((currentPage - 1) * 6).Take(6).ToList(), langCulture, langCode, "240", "160");

            // Title
            ps.pageTitleBind(item, helperPage, langId);

            return View(helperPage);
        }
        public void sharedCheckoutItemLoad(int pageId, helperCheckoutShared pageHelper, checkoutProcess checkoutItem)
        {
            pageShared ps = new pageShared(db);

            var pageItem = ps.getPageById(pageId);
            ps.pageTitleBind(pageItem, pageHelper, langId);
            pageHelper.detail = pageItem.detail;
            pageHelper.stepLinkList = checkoutItem.stepLinkList;
            pageHelper.activeStep = checkoutItem.currentStep;
            checkoutItem.lastSuccessStep = ((checkoutStep)((int)checkoutItem.currentStep - 1));

            if (TempData["errorMessage"] != null)
            {
                pageHelper.isMessageExist = true;
                pageHelper.message = TempData["errorMessage"].ToString();
            }
        }
        public ActionResult Dashboard(int pageId)
        {
            topCart cartItem = (topCart)ViewData["topCart"];
            pageShared ps = new pageShared(db);
            userShared us = new userShared(db);
            addressShared ash = new addressShared(db);

            var pageItem = ps.getPageById(pageId);
            var mainAccountPage = db.tbl_page.Include("tbl_category").Where(a => a.pageTypeId == (int)pageType.account).FirstOrDefault();

            helperDashboard pageHelper = new helperDashboard();

            ps.pageTitleBind(pageItem, pageHelper, langId);
            pageHelper.setTitle(pageItem.name);
            pageHelper.detail = pageItem.detail;

            pageHelper.leftMenuList = generateLeftMenu(mainAccountPage, pageItem.url);
            pageHelper.breadCrumbItem = getBreadCrumbTwoPage(mainAccountPage.name, mainAccountPage.url, pageItem.name, pageItem.url);

            // User Info
            var userItem = us.getUserById(cartItem.userId);
            pageHelper.email = userItem.email;
            pageHelper.nameSurname = userItem.name + " " + userItem.surname;
            var newsletterPage = ps.getPageByType(pageType.accountUserInfo, langId);
            pageHelper.registerInfoLink = langCode + "/" + mainAccountPage.url + "/" + newsletterPage.url + ".html";

            // Newsletter
            var newsletterItem = db.tbl_newsletterUser.Where(a => a.email == userItem.email).FirstOrDefault();

            if (newsletterItem != null)
            {
                pageHelper.isNewsletterRegister = true;
            }

            // Address
            var addressList = ash.getAddressListByUserId(cartItem.userId);
            if (addressList != null && addressList.Count > 0)
            {
                pageHelper.lastAddressItem = addressList.LastOrDefault();
            }
            var addressPage = ps.getPageByType(pageType.accountAddress, langId);
            pageHelper.registerAddressLink = langCode + "/" + mainAccountPage.url + "/" + addressPage.url + ".html";

            //Order
            var pageOrder = ps.getPageByType(pageType.accountOrders, langId);
            pageHelper.registerOrderLink = langCode + "/" + mainAccountPage.url + "/" + pageOrder.url + ".html";
            pageHelper.lastOrder = null; // ToDo: After The order

            return View(pageHelper);
        }
        public ActionResult DiscountIndex(int pageId)
        {
            pageShared ps = new pageShared(db);
            userShared us = new userShared(db);
            addressShared ash = new addressShared(db);

            var pageItem = ps.getPageById(pageId);
            var mainAccountPage = db.tbl_page.Include("tbl_category").Where(a => a.pageTypeId == (int)pageType.account).FirstOrDefault();

            helperDiscount pageHelper = new helperDiscount();

            ps.pageTitleBind(pageItem, pageHelper, langId);
            pageHelper.setTitle(pageItem.name);
            pageHelper.detail = pageItem.detail;

            pageHelper.leftMenuList = generateLeftMenu(mainAccountPage, pageItem.url);
            pageHelper.breadCrumbItem = getBreadCrumbTwoPage(mainAccountPage.name, mainAccountPage.url, pageItem.name, pageItem.url);

            return View(pageHelper);
        }
        public ActionResult ForgetPassword(int pageId)
        {
            helperForgetPassword helperPage = new helperForgetPassword();
            pageShared ps = new pageShared(db);

            var pageItem = ps.getPageById(pageId);

            if (pageItem == null)
            {
                return null;
            }

            ps.pageTitleBind(pageItem, helperPage, langId);
            helperPage.setTitle(pageItem.name);
            helperPage.breadCrumbItem = getBreadCrumbStaticPage(pageItem.name);

            var loginPage = ps.getPageByType(pageType.registerLogin, langId);

            if (loginPage != null)
            {
                helperPage.loginLink = langCode + "/" + loginPage.url + ".html";
            }

            return View(helperPage);
        }
        public ActionResult OrderIndex(int pageId)
        {
            pageShared ps = new pageShared(db);
            userShared us = new userShared(db);
            topCart cartItem = (topCart)ViewData["topCart"];

            var pageMainAccount = db.tbl_page.Include("tbl_category").Where(a => a.pageTypeId == (int)pageType.account).FirstOrDefault();

            var orderSearchPage = ps.getPageByType(pageType.accountOrderSearch, langId);
            var orderDetailPage = ps.getPageByType(pageType.accountOrderDetail, langId);

            if (!cartItem.isRegisteredUser)
            {
                return Redirect("~/" + langCode + "/" + orderSearchPage.url + ".html");
            }

            var pageItem = ps.getPageById(pageId);

            helperOrder pageHelper = new helperOrder();

            ps.pageTitleBind(pageItem, pageHelper, langId);
            pageHelper.setTitle(pageItem.name);
            pageHelper.detail = pageItem.detail;
            pageHelper.breadCrumbItem = getBreadCrumbStaticPage(pageItem.name);
            pageHelper.leftMenuList = generateLeftMenu(pageMainAccount, pageItem.url);

            string orderDatailLinkPrefix = langCode + "/" + orderDetailPage.url + ".html?orderGuid=";
            pageHelper.orderList = getOrderList(orderDatailLinkPrefix, cartItem.userId, true);

            return View(pageHelper);
        }
        public ActionResult ForgetPassword(int pageId, string email)
        {
            System.Threading.Thread.Sleep(1500);

            helperForgetPassword helperPage = new helperForgetPassword();

            pageShared ps = new pageShared(db);
            userShared us = new userShared(db);

            email = email.ToLower(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));

            var pageItem = ps.getPageById(pageId);
            var pageLoginRegister = ps.getPageByType(pageType.registerLogin, langId);

            if (pageItem == null | pageLoginRegister == null)
            {
                return null;
            }

            helperPage.loginLink = langCode + "/" + pageLoginRegister.url + ".html";
            ps.pageTitleBind(pageItem, helperPage, langId);
            helperPage.setTitle(pageItem.name);
            helperPage.breadCrumbItem = getBreadCrumbStaticPage(pageItem.name);

            if (string.IsNullOrWhiteSpace(email))
            {
                helperPage.isMessageExist = true;
                helperPage.message = getErrorMessage(App_GlobalResources.lang.formValidEmail);
                return View(helperPage);
            }

            var userRegisterStatuItem = us.getUserRegisterStatuByEmail(email);
            string message = "";

            switch (userRegisterStatuItem)
            {
                case registerStatu.registered:

                    try
                    {
                        mailShared ms = new mailShared(db, langId);

                        var userItem = db.tbl_user.Where(a => a.email == email).FirstOrDefault();

                        // Add Forget Table
                        var forgetCodeItem = us.addForgetPasswordWithItem(userItem.userId);

                        // Send Mail
                        var mailItem = ms.getResetPasswordMailContent(userItem.name, userItem.surname, forgetCodeItem.code, getSiteName(Request), langCode);
                        mailSend(userItem.email, mailItem.Item1, mailItem.Item2);

                        message = getSuccesMessage(App_GlobalResources.lang.forgetPasswordSuccess).Replace("[email]", email);
                        helperPage.email = "";
                    }
                    catch (Exception ex)
                    {

                        errorSend(ex, "Şifre sıfırlama", true);
                    }

                    break;
                case registerStatu.waitingActivation:

                    var pageMailResent = ps.getPageByType(pageType.activationResent, langId);

                    message = App_GlobalResources.lang.activationNoApprove;
                    message = message.Replace("[email]", email);
                    if (pageMailResent != null)
                    {
                        message = message.Replace("[activationResent]", (Url.Content("~/") + langCode + "/" + pageMailResent.url + ".html"));
                    }

                    message = getErrorMessage(message);

                    break;
                case registerStatu.ban:

                    message = getErrorMessage(App_GlobalResources.lang.forgetPasswordError);

                    break;
                case registerStatu.unregistered:

                    message = getErrorMessage(App_GlobalResources.lang.forgetPasswordError);

                    break;

            }

            helperPage.isMessageExist = true;
            helperPage.message = message;
            return View(helperPage);
        }
        public ActionResult OrderSearch(helperOrderSearch pageHelper, int pageId)
        {
            topCart cartItem = (topCart)ViewData["topCart"];
            pageShared ps = new pageShared(db);

            var pageMainAccount = db.tbl_page.Include("tbl_category").Where(a => a.pageTypeId == (int)pageType.account).FirstOrDefault();

            if (cartItem.isRegisteredUser)
            {
                var pageOrderList = ps.getPageByType(pageType.accountOrders, langId);
                return Redirect("~/" + langCode + "/" + pageMainAccount.url + "/" + pageOrderList.url + ".html");
            }

            var pageItem = db.tbl_page.Include("tbl_category").Where(a => a.pageId == pageId).FirstOrDefault();
            ps.pageTitleBind(pageItem, pageHelper, langId);
            pageHelper.detail = pageItem.detail;
            pageHelper.breadCrumbItem = getBreadCrumbStaticPage(pageItem.name);

            var parentCategoryList = db.tbl_category.Include("tbl_page").Where(a => a.parentId == pageItem.tbl_category.parentId && a.statu).ToList();
            pageHelper.leftMenuList = getStaticLeftMenu(parentCategoryList, pageId);

            // Redirect to Login Page With Session
            if (!string.IsNullOrWhiteSpace(pageHelper.toLogin))
            {
                Session["redirectPage"] = Request.Url.ToString();

                var loginPage = ps.getPageByType(pageType.registerLogin, langId);
                if (loginPage == null)
                {
                    errorSend(new Exception("loginPage gelmemesi, checkout Step 0"), "LoginPage gelmemesi, checkout Step 0", true);
                    return null;
                }

                return Redirect("~/" + langCode + "/" + loginPage.url + ".html");
            }
            else // Search Order
            {
                if (ModelState.IsValid)
                {

                    orderShared os = new orderShared(db);
                    var orderItem = os.getUnregisteredOrder(pageHelper.email, pageHelper.orderNo);

                    if (orderItem != null)
                    {
                        var orderDetailPage = ps.getPageByType(pageType.accountOrderDetail, langId);
                        return Redirect("~/" + langCode + "/" + orderDetailPage.url + ".html?orderGuid=" + orderItem.orderGuid);
                    }
                    else
                    {
                        pageHelper.isMessageExist = true;
                        pageHelper.message = getErrorMessage(lang.orderSearchNotFound);
                        return View(pageHelper);
                    }

                }
                else
                {
                    pageHelper.isMessageExist = true;
                    pageHelper.message = getErrorMessage(getModelStateError(ModelState));
                    return View(pageHelper);
                }
            }
        }
        public ActionResult ActivationResent(int pageId, string email)
        {
            System.Threading.Thread.Sleep(1500);

            helperActivationResent helperPage = new helperActivationResent();

            pageShared ps = new pageShared(db);

            email = email.ToLower(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));

            var pageItem = ps.getPageById(pageId);
            var pageLoginRegister = ps.getPageByType(pageType.registerLogin, langId);

            if (pageItem == null | pageLoginRegister == null)
            {
                return null;
            }

            helperPage.loginLink = langCode + "/" + pageLoginRegister.url + ".html";
            ps.pageTitleBind(pageItem, helperPage, langId);
            helperPage.setTitle(pageItem.name);
            helperPage.breadCrumbItem = getBreadCrumbStaticPage(pageItem.name);

            if (string.IsNullOrWhiteSpace(email))
            {
                helperPage.isMessageExist = true;
                helperPage.message = getErrorMessage(App_GlobalResources.lang.formValidEmail);
                return View(helperPage);
            }

            var userItem = db.tbl_user.Where(a => a.email == email && a.registerStatuId == (int)registerStatu.waitingActivation).FirstOrDefault();

            if (userItem != null)
            {
                try
                {
                    tbl_activation activationItem = new tbl_activation();

                    activationItem.code = Guid.NewGuid().ToString();
                    activationItem.datetime = DateTime.Now;
                    activationItem.userId = userItem.userId;

                    db.tbl_activation.Add(activationItem);
                    db.SaveChanges();

                    mailShared ms = new mailShared(db, langId);
                    var mailItem = ms.getActivationMailContent(userItem.name, userItem.surname, activationItem.code, getSiteName(Request), langCode);

                    mailSend(userItem.email, mailItem.Item1, mailItem.Item2);

                    helperPage.isMessageExist = true;
                    helperPage.message = getSuccesMessage(App_GlobalResources.lang.activationResentSuccess);
                    helperPage.email = "";
                    return View(helperPage);

                }
                catch (Exception ex)
                {
                    errorSend(ex, "Activation Update", true);
                    helperPage.isMessageExist = true;
                    helperPage.message = getErrorMessage(App_GlobalResources.lang.unexpectedErrorMsg);
                    return View(helperPage);
                }
            }
            else
            {
                helperPage.isMessageExist = true;
                string errorMessage = App_GlobalResources.lang.activationResentMailErrorNoUser;
                var registerPage = db.tbl_page.Where(a => a.langId == langId && a.pageTypeId == (int)pageType.registerLogin).FirstOrDefault();

                if (registerPage != null)
                {
                    errorMessage = errorMessage.Replace("[registerPage]", getSiteName(Request) + langCode + "/" + registerPage.url + ".html");
                }

                helperPage.message = getErrorMessage(errorMessage);
                return View(helperPage);
            }
        }
        public ActionResult UserInfo(int pageId, helperUserInfo pageHelper)
        {
            pageShared ps = new pageShared(db);
            userShared us = new userShared(db);
            addressShared ash = new addressShared(db);

            var pageItem = ps.getPageById(pageId);
            var mainAccountPage = db.tbl_page.Include("tbl_category").Where(a => a.pageTypeId == (int)pageType.account).FirstOrDefault();

            ps.pageTitleBind(pageItem, pageHelper, langId);
            pageHelper.setTitle(pageItem.name);
            pageHelper.detail = pageItem.detail;

            pageHelper.leftMenuList = generateLeftMenu(mainAccountPage, pageItem.url);
            pageHelper.breadCrumbItem = getBreadCrumbTwoPage(mainAccountPage.name, mainAccountPage.url, pageItem.name, pageItem.url);
            pageHelper.cancelUrl = langCode + "/" + mainAccountPage.url + ".html";

            DateTime birthday = DateTime.Now;

            try
            {
                birthday = new DateTime(pageHelper.year, pageHelper.month, pageHelper.day);
            }
            catch
            {
                ModelState.AddModelError("validDate", lang.formValidDate);
            }

            try
            {
                System.Net.Mail.MailAddress mailItem = new System.Net.Mail.MailAddress(pageHelper.email);
            }
            catch
            {
                ModelState.AddModelError("email", lang.formValidEmail);
            }

            if (ModelState.IsValid)
            {
                topCart cartItem = (topCart)ViewData["topCart"];
                var userItem = us.getUserById(cartItem.userId);

                try
                {
                    userItem.birthday = birthday;
                    userItem.email = pageHelper.email;
                    userItem.gender = pageHelper.gender;
                    userItem.name = pageHelper.name;
                    userItem.surname = pageHelper.surname;
                    db.SaveChanges();

                    pageHelper.message = getSuccesMessage(lang.userInfoUpdated, "autoHide");
                    pageHelper.isMessageExist = true;
                }
                catch (Exception ex)
                {
                    errorSend(ex, "userAccountUpdate", true);
                }

            }
            else
            {
                string messages = string.Join("<br/> ", ModelState.Values
                                        .SelectMany(x => x.Errors)
                                        .Select(x => x.ErrorMessage));

                pageHelper.message = getErrorMessage(messages, "autoHide");
                pageHelper.isMessageExist = true;
            }

            return View(pageHelper);
        }
        public ActionResult Index(int pageId)
        {
            pageShared ps = new pageShared(db);

            var helperItem = new ViewModel.LoginRegister.helperLoginRegister();

            // Registered User Redirect
            if (ViewData["topCart"] != null)
            {
                var cartItem = (topCart)ViewData["topCart"];
                if (cartItem.isRegisteredUser)
                {
                    return Redirect("~/");
                }
            }

            helperItem.register = new ViewModel.LoginRegister.registerItem();
            var aggrementModule = ps.getModuleByType(moduleType.registerAgreement, langId);
            if (aggrementModule != null)
            {
                helperItem.register.agreementContent = aggrementModule.htmlContent;
            }

            helperItem.login = new ViewModel.LoginRegister.loginItem();

            var pageItem = ps.getPageById(pageId);
            if (pageItem == null)
            {
                return null;
            }

            ps.pageTitleBind(pageItem, helperItem, langId);
            var pageName = pageItem.name;
            if (!string.IsNullOrWhiteSpace(pageItem.title))
            {
                pageName = pageItem.title;
            }

            // forget Password Link
            var forgetPasswordPage = ps.getPageByType(pageType.forgetPassword, langId);
            if (forgetPasswordPage != null)
            {
                helperItem.login.forgetPasswordUrl = langCode + "/" + forgetPasswordPage.url + ".html";
            }

            // Facebook Register & login Error
            if (Request.QueryString["facebookError"] != null && Request.QueryString["facebookError"].ToString() == "yes")
            {
                helperItem.isFacebookError = true;
                helperItem.facebookErrorMessage = getErrorMessage(App_GlobalResources.lang.unexpectedErrorMsg);
            }

            if (Request.QueryString["needLogin"] != null && Request.QueryString["needLogin"].ToString() == "yes")
            {
                helperItem.isLoginRequeredShown = true;
                helperItem.isLoginRequeredMessage = getErrorMessage(App_GlobalResources.lang.needLogin, "mTop10 mBottom0 autoHide");
            }

            helperItem.breadCrumbItem = getBreadCrumbStaticPage(pageName);

            return View(helperItem);
        }