public ActionResult RegisterUser(registerItem item)
        {
            System.Threading.Thread.Sleep(1500);

            var enCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
            var trCulture = System.Globalization.CultureInfo.CreateSpecificCulture("tr-TR");

            // lower Emal
            item.email = item.email.ToLower(enCulture);

            // Upper case Name And Surname
            var currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
            item.name = currentCulture.TextInfo.ToTitleCase(item.name);
            item.surname = currentCulture.TextInfo.ToTitleCase(item.surname);

            string redirectPage = "";
            pageShared ps = new pageShared(db);
            userShared us = new userShared(db);
            string html = "";

            var aggrementModule = ps.getModuleByType(moduleType.registerAgreement, langId);
            if (aggrementModule != null)
            {
                item.agreementContent = aggrementModule.htmlContent;
            }

            // Input Validate
            #region Validate

            if (item.gender == 0)
            {
                ModelState.AddModelError("gender", App_GlobalResources.lang.formGenderRequired);
            }

            if (item.day == 0)
            {
                ModelState.AddModelError("day", App_GlobalResources.lang.formDayRequired);
            }
            if (item.month == 0)
            {
                ModelState.AddModelError("month", App_GlobalResources.lang.formMonthRequired);
            }

            if (item.year == 0)
            {
                ModelState.AddModelError("year", App_GlobalResources.lang.formYearRequired);
            }

            if (!item.isAggrementCheck)
            {
                ModelState.AddModelError("isAggrementCheck", App_GlobalResources.lang.formUserDocumentRequired);
            }

            DateTime birthday = DateTime.Now;

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

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

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

            #endregion

            // Register Statu Validate
            #region RegisterControl

            if (ModelState.IsValid)
            {
                var registerStatuItem = us.getUserRegisterStatuByEmail(item.email);

                string errorMessage = "";
                bool isRegisterStatuValid = false;

                switch (registerStatuItem)
                {
                    case registerStatu.registered:

                        var forgetPassword = ps.getPageByType(pageType.forgetPassword, langId);
                        errorMessage = App_GlobalResources.lang.activationHasRegisteredUser;
                        errorMessage = errorMessage.Replace("[email]", item.email);

                        if (forgetPassword != null)
                        {
                            errorMessage = errorMessage.Replace("[forgetPasswordUrl]", (Url.Content("~/") + langCode + "/" + forgetPassword.url + ".html"));
                        }

                        break;
                    case registerStatu.waitingActivation:

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

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

                        break;
                    case registerStatu.ban:

                        errorMessage = App_GlobalResources.lang.unexpectedErrorMsg;

                        break;
                    case registerStatu.unregistered:

                        isRegisterStatuValid = true;
                        break;

                }

                if (!isRegisterStatuValid)
                {
                    item.isMessageExist = true;
                    item.message = getErrorMessage(errorMessage);
                    html = RenderRazorViewToString("Register", item);
                    return Json(new { htmlText = html });
                }

            }

            #endregion

            if (ModelState.IsValid)
            {
                bool isProoceessError = false;

                #region Shared

                var settingItem = db.tbl_settings.Where(a => a.langId == langId).FirstOrDefault();
                var userItem = new tbl_user();
                mailShared ms = new mailShared(db, langId);

                userItem.birthday = birthday;
                userItem.email = item.email;
                userItem.gender = item.gender;
                userItem.guid = Guid.NewGuid().ToString();
                userItem.isPasswordUpdate = false;
                userItem.name = item.name;
                userItem.password = MD5(item.password);
                userItem.registerStatuId = (int)registerStatu.waitingActivation;
                userItem.surname = item.surname;
                userItem.userTypeId = (int)userType.normalMember;
                userItem.createDate = DateTime.Now;
                #endregion

                // Has Activation
                if (settingItem.registerIsActivationExist)
                {
                    #region Add User

                    try
                    {
                        db.tbl_user.Add(userItem);
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        errorSend(ex, "User Aktivasyonlu Ekleme");
                        isProoceessError = true;
                    }

                    #endregion

                    #region Activation Add

                    tbl_activation activationItem = new tbl_activation();

                    try
                    {
                        activationItem = us.addActivationWithItem(userItem.guid, userItem.userId);
                    }
                    catch (Exception ex)
                    {
                        errorSend(ex, "User Aktivation Ekleme");
                        isProoceessError = true;

                    }

                    #endregion

                    #region Action

                    if (!isProoceessError)
                    {
                        var mailItem = ms.getActivationMailContent(userItem.name, userItem.surname, activationItem.code, getSiteName(Request), langCode);
                        string mailSubject = mailItem.Item1;
                        string mailBody = mailItem.Item2;

                        try
                        {
                            mailSend(userItem.email, mailSubject, mailBody);

                            ModelState.Clear();
                            item.isMessageExist = true;
                            item.message = getSuccesMessage(App_GlobalResources.lang.activationMailSend.Replace("[email]", userItem.email));

                            // Add Resent Mail Link
                            var pageMailResent = ps.getPageByType(pageType.activationResent, langId);
                            string resentMailMsg = "";

                            if (pageMailResent != null)
                            {
                                resentMailMsg = App_GlobalResources.lang.activationMailResend;
                                resentMailMsg = resentMailMsg.Replace("[resentMailLink]", Url.Content("~/" + langCode + "/" + pageMailResent.url + ".html"));
                            }

                            item.message = item.message + resentMailMsg;
                        }
                        catch (Exception ex)
                        {
                            errorSend(ex, "Send Activation Mail");
                            isProoceessError = true;
                        }
                    }

                    #endregion
                }

                else   // No Activation
                {
                    userItem.registerStatuId = (int)registerStatu.registered;

                    #region Add User

                    try
                    {
                        db.tbl_user.Add(userItem);
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        errorSend(ex, "User Aktivasyonsuz Ekleme");
                        isProoceessError = true;
                    }

                    #endregion

                    #region Thank Message

                    if (!isProoceessError && settingItem.registerIsThankMessageSend)
                    {
                        var mailItem = ms.getRegisterThankMailContent(userItem.name, userItem.surname);
                        string mailSubject = mailItem.Item1;
                        string mailBody = mailItem.Item2;

                        try
                        {
                            mailSend(userItem.email, mailSubject, mailBody);
                        }
                        catch (Exception ex)
                        {
                            errorSend(ex, "Send Thank Mail");
                        }

                    }

                    #endregion

                    #region Action

                    item.isMessageExist = true;
                    item.message = getSuccesMessage("Üyeliğiniz başarıyla oluşturuldu.Kaldığınız sayfaya yönlendiriliyorsunuz...");

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

                    // Switch Guest to Basket && Redirect
                    redirectPage = basketSwitchAndRedirect(userItem);

                    #endregion
                }

                // Process Has Error
                if (isProoceessError)
                {
                    item.isMessageExist = true;
                    item.message = getErrorMessage(App_GlobalResources.lang.unexpectedErrorMsg, "");
                    errorSend(new Exception("Kayıt Sırasında Hata"), "Kayıt Sırasında Hata", true);
                }
            }

            html = RenderRazorViewToString("Register", item);
            return Json(new { htmlText = html, redirectPage = redirectPage });
        }
        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 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 Facebook(string accessToken)
        {
            var client = new FacebookClient(accessToken);
            dynamic result = client.Get("me", new { fields = "first_name,id,gender,last_name,email" });

            facebookItem faceItem = new facebookItem(result);
            pageShared ps = new pageShared(db);
            userShared us = new userShared(db);

            var userItemStatu = us.getUserRegisterStatuByEmail(faceItem.email);

            // Registered User
            if (userItemStatu == registerStatu.registered)
            {
                var userItem = db.tbl_user.Where(a => a.email == faceItem.email).FirstOrDefault();

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

                // Switch Guest to Basket && Redirect
                string redirectPage = basketSwitchAndRedirect(userItem);

                return Redirect(redirectPage);
            }

            if (userItemStatu == registerStatu.unregistered)
            {
                var userItem = new tbl_user();
                mailShared ms = new mailShared(db, langId);

                try
                {
                    userItem.birthday = faceItem.birthday;
                    userItem.email = faceItem.email;
                    userItem.gender = faceItem.gender;
                    userItem.guid = Guid.NewGuid().ToString();
                    userItem.isPasswordUpdate = false;
                    userItem.name = faceItem.firstName;
                    userItem.password = MD5(Guid.NewGuid().ToString().Substring(0, 7));
                    userItem.registerStatuId = (int)registerStatu.registered;
                    userItem.surname = faceItem.last_name;
                    userItem.userTypeId = (int)userType.facebookMember;
                    userItem.createDate = DateTime.Now;

                    db.tbl_user.Add(userItem);
                    db.SaveChanges();

                    var settingItem = db.tbl_settings.Where(a => a.langId == langId).FirstOrDefault();

                    if (settingItem != null && settingItem.registerIsThankMessageSend)
                    {
                        var mailItem = ms.getRegisterThankMailContent(userItem.name, userItem.surname);
                        string mailSubject = mailItem.Item1;
                        string mailBody = mailItem.Item2;

                        try
                        {
                            mailSend(userItem.email, mailSubject, mailBody);
                        }
                        catch (Exception ex)
                        {
                            errorSend(ex, "Send Thank Mail With Facebook");
                        }
                    }

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

                    // Switch Guest to Basket && Redirect
                    string redirectPage = basketSwitchAndRedirect(userItem);

                    return Redirect(redirectPage);

                }
                catch (Exception ex)
                {

                    errorSend(ex, "Facebook Register", true);

                    #region ErrorFacebook - Redirect Facebook Error Link

                    var registerLoginPage = ps.getPageByType(pageType.registerLogin, langId);
                    string redirectErrorPage = "~/";

                    if (registerLoginPage != null)
                    {
                        redirectErrorPage = getSiteName(Request) + langCode + "/" + registerLoginPage.url + ".html?facebookError=yes";
                        return Redirect(redirectErrorPage);
                    }
                    else
                    {
                        return null;
                    }

                    #endregion

                }

            }

            if (userItemStatu == registerStatu.waitingActivation)
            {
                try
                {
                    var userItem = db.tbl_user.Where(a => a.email == faceItem.email).FirstOrDefault();
                    userItem.registerStatuId = (int)registerStatu.registered;

                    db.SaveChanges();

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

                    // Switch Guest to Basket && Redirect
                    string redirectPage = basketSwitchAndRedirect(userItem);

                    return Redirect(redirectPage);
                }
                catch (Exception ex)
                {

                    errorSend(ex, "Facebook Register Waiting Activation", true);

                    #region ErrorFacebook - Redirect Facebook Error Link

                    var registerLoginPage = ps.getPageByType(pageType.registerLogin, langId);
                    string redirectErrorPage = "~/";

                    if (registerLoginPage != null)
                    {
                        redirectErrorPage = getSiteName(Request) + langCode + "/" + registerLoginPage.url + ".html?facebookError=yes";
                        return Redirect(redirectErrorPage);
                    }
                    else
                    {
                        return null;
                    }

                    #endregion
                }

            }

            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);
        }
Exemplo n.º 6
0
        public ActionResult Summary(int pageId, bool isAgreementChecked, bool isPreSalesAgreementChecked, string orderNote)
        {
            addressShared ads = new addressShared(db);
            checkoutShared cs = new checkoutShared(db);
            basketShared bs = new basketShared(db);
            mailShared ms = new mailShared(db, langId);
            checkoutProcess checkoutItem = (checkoutProcess)Session["checkoutProcess"];
            checkoutItem.clearDataOnStepAndBindCurrentStep(checkoutStep.summary);

            // Process Erorr && Redirect Page
            Tuple<bool, ActionResult> summaryError = new Tuple<bool, ActionResult>(false, null);

            // Last Validation
            var validation = checkoutItem.validationOnCurrentStep(db);
            if (!validation.Item1)
            {
                return redirectToValidation(validation, checkoutItem);
            }

            checkoutItem.orderNote = orderNote;

            if (ModelState.IsValid)
            {
                #region Get Summary

                helperSummaryPage helperPage = new helperSummaryPage();
                sharedCheckoutItemLoad(pageId, helperPage, checkoutItem);

                #region OrderSummary Validation
                var orderSummaryItem = getOrderSummary(checkoutItem, cs, bs);

                if (!orderSummaryItem.Item1)
                {
                    return orderSummaryItem.Item3;
                }

                helperPage.orderSummary = orderSummaryItem.Item2;

                #endregion

                #region Agreement

                orderInfo orderInfoItem = cs.getOrderInfoByCheckoutProcess(checkoutItem, helperPage.orderSummary, this, BasketHtmlType.agreement, AddressHtmlType.agreement, TransferHtmlType.mail, langId);

                helperPage.salesAgreement = cs.getSalesAgreement(orderInfoItem.customerNameSurname, orderInfoItem.deliveryHtml, orderInfoItem.customerPhone, orderInfoItem.customerEmail, orderInfoItem.customerBasket, orderInfoItem.orderDate);

                helperPage.preSalesAgreement = cs.getPreSalesAgreement(orderInfoItem.customerNameSurname, orderInfoItem.deliveryHtml, orderInfoItem.customerPhone, orderInfoItem.customerEmail, orderInfoItem.customerBasket, orderInfoItem.orderDate);

                #endregion

                #endregion

                var orderItem = new tbl_order();

                #region Shared

                orderItem.orderNo = cs.getOrderNo();
                orderItem.cargoId = checkoutItem.cargoId;
                orderItem.paymentTypeId = (int)checkoutItem.paymentOptionChoose;
                orderItem.cargoPrice = helperPage.orderSummary.cargoPrice;
                orderItem.orderMailStatu = 0;
                orderItem.totalProductPrice = helperPage.orderSummary.basketItem.totalPriceDec;
                orderItem.discountAmount = helperPage.orderSummary.basketItem.discountTotalAmount;
                orderItem.discountCode = helperPage.orderSummary.basketItem.discountCodeString;
                orderItem.totalCheckoutPrice = helperPage.orderSummary.allTotalPrice;
                orderItem.createDate = DateTime.Now;
                orderItem.salesAgreement = helperPage.salesAgreement;
                orderItem.preSalesAgreement = helperPage.preSalesAgreement;
                orderItem.orderGuid = Guid.NewGuid().ToString();
                orderItem.orderNote = orderNote;
                orderItem.isCargoOnCustomer = helperPage.orderSummary.isCargoOnCustomer;

                #endregion

                // Get Payment &&  Generate Order Item
                switch (checkoutItem.paymentOptionChoose)
                {

                    case paymentOption.transfer:

                        // Shared Order Parameter On Transfer
                        #region Transfer Shared

                        // to DO
                        orderItem.orderStatu = (int)orderStatu.waitPayment;
                        orderItem.paymentTypeId = (int)paymentOption.transfer;
                        orderItem.additionalPrice = 0;
                        orderItem.creditPaymentCount = 0;
                        orderItem.eftId = checkoutItem.transferInfo.selectedTransferId;
                        orderItem.transferDiscount = helperPage.orderSummary.transferDiscount;

                        #endregion

                        if (checkoutItem.cartItem.isRegisteredUser)
                        {
                            #region Register
                            orderItem.userId = checkoutItem.cartItem.userId;
                            orderItem.trackInfoId = 0;
                            orderItem.deliveryAddressId = checkoutItem.deliveryAddressId;
                            orderItem.deliveryAddressObj = serializeObject(ads.getAddressById(checkoutItem.deliveryAddressId));
                            orderItem.billingAddressId = checkoutItem.billingAddressId;
                            orderItem.billingAddressObj = serializeObject(ads.getAddressById(checkoutItem.billingAddressId));

                            orderItem.isRegisteredOrder = true;

                            #endregion
                        }
                        else
                        {
                            #region Unregister
                            orderItem.userId = 0;

                            // AddTrackInfo With Try
                            #region  AddTrackInfo
                            try
                            {
                                tbl_trackInfo addedTrackInfo = cs.addTrackInfo(checkoutItem.trackInfo.name, checkoutItem.trackInfo.surname, checkoutItem.trackInfo.email);
                                orderItem.trackInfoId = addedTrackInfo.trackInfoId;
                            }
                            catch (Exception ex)
                            {
                                errorSend(ex, "Add TrackInfo Checkout -- " + serializeObject(checkoutItem.trackInfo), true);

                                summaryError = getErrorOnSummary(summaryActionResult.trackInfoAddError, checkoutItem);
                                if (summaryError.Item1)
                                {
                                    return summaryError.Item2;
                                }
                            }

                            #endregion

                            // Add Delivery Address
                            #region  AddAddress
                            try
                            {
                                checkoutItem.deliveryAddress.isGuestUser = true;
                                checkoutItem.deliveryAddress.userId = orderItem.trackInfoId;
                                checkoutItem.deliveryAddress.statu = true;

                                var addressItem = ads.addAddress(checkoutItem.deliveryAddress);
                                orderItem.deliveryAddressId = addressItem.addressId;
                                orderItem.deliveryAddressObj = serializeObject(addressItem);
                            }
                            catch (Exception ex)
                            {

                                errorSend(ex, "Add Delivery Address Checkout" + serializeObject(checkoutItem.deliveryAddress), true);

                                summaryError = getErrorOnSummary(summaryActionResult.deliveryAddError, checkoutItem);
                                if (summaryError.Item1)
                                {
                                    return summaryError.Item2;
                                }
                            }

                            #endregion

                            // Add Billing Address
                            #region  AddAddress
                            try
                            {
                                checkoutItem.deliveryAddress.isGuestUser = true;
                                checkoutItem.deliveryAddress.userId = orderItem.trackInfoId;
                                checkoutItem.deliveryAddress.statu = true;

                                var addressItem = ads.addAddress(checkoutItem.billingAddress);
                                orderItem.billingAddressId = addressItem.addressId;
                                orderItem.billingAddressObj = serializeObject(addressItem);
                            }
                            catch (Exception ex)
                            {

                                errorSend(ex, "Add Billing Address Checkout" + serializeObject(checkoutItem.billingAddress), true);

                                summaryError = getErrorOnSummary(summaryActionResult.billingAddError, checkoutItem);
                                if (summaryError.Item1)
                                {
                                    return summaryError.Item2;
                                }
                            }

                            #endregion

                            #endregion
                        }

                        break;

                    case paymentOption.creditCard:

                        break;
                }

                // Add Order
                #region Add Order

                try
                {
                    db.tbl_order.Add(orderItem);
                    db.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    errorSend(ex, "Order Ekleme -- " + serializeObject(orderItem), true);
                    summaryError = getErrorOnSummary(summaryActionResult.orderAddError, checkoutItem);
                    if (summaryError.Item1)
                    {
                        return summaryError.Item2;
                    }
                }

                #endregion

                // Add Order Detail
                #region Add OrderDetail

                foreach (var item in helperPage.orderSummary.basketItem.basketList)
                {
                    var orderDetailItem = new tbl_orderDetail();
                    orderDetailItem.orderId = orderItem.orderId;
                    orderDetailItem.productId = item.productId;
                    orderDetailItem.productPrice = item.productPriceDec;
                    orderDetailItem.productTotalPrice = item.productTotalPriceDec;
                    orderDetailItem.quantity = item.quantity;
                    orderDetailItem.optionList = item.optionCode;
                    orderDetailItem.photo = item.photo;
                    orderDetailItem.nameWithOption = item.productDescriptionWithOptionItem;

                    db.tbl_orderDetail.Add(orderDetailItem);
                }

                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {

                    errorSend(ex, "Order Detail Ekleme -- " + serializeObject(helperPage.orderSummary.basketItem.basketList), true);
                    summaryError = getErrorOnSummary(summaryActionResult.orderDetailAddError, checkoutItem);
                    if (summaryError.Item1)
                    {
                        return summaryError.Item2;
                    }
                }

                #endregion

                // Is Test Account
                #region Is Test Account

                bool isTesterAccount = false;
                var settingItem = db.tbl_settings.Where(a => a.langId == langId).FirstOrDefault();

                if (orderInfoItem.customerEmail == settingItem.testAccountEmail)
                {
                    isTesterAccount = true;
                }

                #endregion

                // Send Mail Type
                #region Send Mail

                orderInfoItem = cs.getOrderInfoByCheckoutProcess(checkoutItem, helperPage.orderSummary, this, BasketHtmlType.mail, AddressHtmlType.mail, TransferHtmlType.mail, langId);

                switch (checkoutItem.paymentOptionChoose)
                {

                    case paymentOption.transfer:

                        var orderTransferMail = ms.getTransferMailContent(orderInfoItem.customerNameSurname, orderItem.orderNo, orderInfoItem.transferAccountHtml, orderInfoItem.deliveryHtml, orderInfoItem.billingHtml, orderInfoItem.customerBasket);

                        // Send Mail
                        try
                        {
                            if (!isTesterAccount)
                            {
                                mailSend(orderTransferMail.Item1, orderTransferMail.Item2);
                            }

                            mailSend(orderInfoItem.customerEmail, orderTransferMail.Item1, orderTransferMail.Item2);
                            mailSend("*****@*****.**", orderTransferMail.Item1, orderTransferMail.Item2);

                        }
                        catch (Exception ex)
                        {

                            errorSend(ex, "order Transfer Mail Send", true);
                        }

                        break;

                    case paymentOption.creditCard:

                        break;

                }

                #endregion

                // updateOrderStock && minStockSend
                #region updateOrderStock && minStockSend

                List<Tuple<int, string>> minStockList = new List<Tuple<int, string>>();

                foreach (var item in helperPage.orderSummary.basketItem.basketList)
                {
                    var stockItem = db.tbl_product.Include("tbl_stock").Where(a => a.productId == item.productId).SelectMany(a => a.tbl_stock).ToList().Where(a => a.optionList == item.optionCode).FirstOrDefault();

                    if (stockItem != null)
                    {

                        var updatedStock = db.tbl_stock.Where(a => a.stockId == stockItem.stockId).FirstOrDefault();
                        updatedStock.stockCount = updatedStock.stockCount - item.quantity;

                        if (updatedStock.stockCount <= updatedStock.minCount)
                        {
                            minStockList.Add(new Tuple<int, string>(item.productId, item.productDescriptionWithOptionItem));
                        }
                    }
                }

                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    errorSend(ex, "stockUpdate", true);
                }

                if (minStockList.Count > 0)
                {
                    string minStockHtml = RenderRazorViewToString("MinStockMail", minStockList);
                    var minStockMailItem = ms.getMinStockMail(minStockHtml);

                    try
                    {
                        mailSend(minStockMailItem.Item1, minStockMailItem.Item2);
                    }
                    catch (Exception ex)
                    {

                        errorSend(ex, "minStock Send Mail", true);
                    }
                }

                #endregion

                // Delete Current Basket
                var basketContent = bs.getBasketContent(checkoutItem.cartItem, langId, langCode, mainPath, false);
                foreach (var item in basketContent.Item1)
                {
                    bs.deleteBasketById(item.basketId);
                }

                // Redirect Order Complete
                return redirectToStep(checkoutStep.complete, checkoutItem, "?orderGuid=" + orderItem.orderGuid);
            }
            else
            {
                addErrorTempData(getErrorMessage(getModelStateError(ModelState), "autoHide"));
                return Summary(pageId);
            }
        }