Пример #1
0
        public ActionResult Billing(int pageId)
        {
            checkoutProcess checkoutItem = (checkoutProcess)Session["checkoutProcess"];
            checkoutItem.clearDataOnStepAndBindCurrentStep(checkoutStep.billing);

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

            // Kayıtlı Üye
            if (checkoutItem.cartItem.isRegisteredUser)
            {
                addressShared ads = new addressShared(db);
                userShared us = new userShared(db);

                helperRegisterBilling helperPage = new helperRegisterBilling();
                sharedCheckoutItemLoad(pageId, helperPage, checkoutItem);
                helperPage.addressList = ads.getAddressListTemplate(checkoutItem.cartItem.userId).OrderByDescending(a => a.addressId).ToList();
                helperPage.selectedBillingAddressId = checkoutItem.billingAddressId;

                helperPage.userguid = checkoutItem.cartItem.userGuid;

                Session["checkoutProcess"] = checkoutItem;
                return View("BillingRegister", helperPage);
            }
            else // Üye olmadan Ödeme
            {
                helperUnRegisterBilling helperPage = new helperUnRegisterBilling();
                sharedCheckoutItemLoad(pageId, helperPage, checkoutItem);

                if (checkoutItem.billingAddress != null)
                {
                    helperPage.addressItem = checkoutItem.billingAddress;
                }
                else
                {
                    if (checkoutItem.isBillingSameAddress && checkoutItem.deliveryAddress != null)
                    {
                        helperPage.addressItem = checkoutItem.deliveryAddress;
                    }
                    else
                    {
                        helperPage.addressItem = new Models.tbl_address();
                    }
                }

                helperPage.addressItem.isPersonal = true;

                Session["checkoutProcess"] = checkoutItem;
                return View("BillingUnRegister", helperPage);

            }
        }
Пример #2
0
        public JsonResult AddressAdd(addressModelItem item)
        {
            System.Threading.Thread.Sleep(1500);

            //Close Url
            pageShared ps = new pageShared(db);
            addressShared ads = new addressShared(db);
            var mainPage = ps.getPageByType(pageType.account, langId);
            var addressPage = ps.getPageByType(pageType.accountAddress, langId);
            item.closeUrl = getSiteName(Request) + langCode + "/" + mainPage.url + "/" + addressPage.url + ".html";
            int addressId = 0;

            userShared us = new userShared(db);
            var userItem = us.getUserByGuid(item.guid);

            if (userItem == null)
            {
                item.isMessageExist = true;
                item.message = getErrorMessage(lang.unexpectedErrorMsg);

                return Json(new { html = RenderRazorViewToString("AddressAdd", item) }, JsonRequestBehavior.AllowGet);
            }

            extraValidation(item);

            if (ModelState.IsValid)
            {

                try
                {
                    item.addressItem.userId = userItem.userId;
                    item.addressItem.statu = true;
                    item.addressItem = ads.addAddress(item.addressItem);

                    item.isMessageExist = true;
                    item.message = getSuccesMessage(lang.addressAddSuccess);
                    item.isSuccess = true;
                    addressId = item.addressItem.addressId;

                }
                catch (Exception ex)
                {
                    errorSend(ex, "Account Address Add", true);

                    item.isMessageExist = true;
                    item.message = getErrorMessage(lang.unexpectedErrorMsg);

                }

            }

            string htmlText = RenderRazorViewToString("AddressAdd", item);
            return Json(new { html = htmlText, addressId = addressId });
        }
Пример #3
0
        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);
        }
Пример #4
0
        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;
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        public JsonResult AddressEdit(string userGuid, int addressId)
        {
            userShared us = new userShared(db);
            addressShared ads = new addressShared(db);

            var userItem = us.getUserByGuid(userGuid);
            var addressItem = ads.getAddressById(addressId);

            addressModelItem item = new addressModelItem();

            if (userItem == null || addressItem == null || addressItem.userId != userItem.userId)
            {
                item.isMessageExist = true;
                item.message = getErrorMessage(lang.unexpectedErrorMsg);
            }

            item.addressItem = addressItem;
            item.guid = userGuid;

            //Close Url
            pageShared ps = new pageShared(db);
            var mainPage = ps.getPageByType(pageType.account, langId);
            var addressPage = ps.getPageByType(pageType.accountAddress, langId);
            item.closeUrl = getSiteName(Request) + langCode + "/" + mainPage.url + "/" + addressPage.url + ".html";

            string htmlText = RenderRazorViewToString("AddressEdit", item);
            return Json(new { html = htmlText }, JsonRequestBehavior.AllowGet);
        }
Пример #9
0
        public JsonResult AddressEdit(addressModelItem item)
        {
            System.Threading.Thread.Sleep(1500);

            //Close Url
            pageShared ps = new pageShared(db);
            addressShared ads = new addressShared(db);
            var mainPage = ps.getPageByType(pageType.account, langId);
            var addressPage = ps.getPageByType(pageType.accountAddress, langId);
            item.closeUrl = getSiteName(Request) + langCode + "/" + mainPage.url + "/" + addressPage.url + ".html";

            userShared us = new userShared(db);
            var userItem = us.getUserByGuid(item.guid);

            if (userItem == null || item.addressItem == null || item.addressItem.userId != userItem.userId)
            {
                item.isMessageExist = true;
                item.message = getErrorMessage(lang.unexpectedErrorMsg, "autoHide");

                return Json(new { html = RenderRazorViewToString("AddressEdit", item) }, JsonRequestBehavior.AllowGet);
            }

            extraValidation(item);

            if (ModelState.IsValid)
            {
                try
                {
                    item.addressItem.userId = userItem.userId;
                    item.addressItem.statu = true;

                    var updateItem = ads.getAddressById(item.addressItem.addressId);
                    db.Entry<tbl_address>(updateItem).CurrentValues.SetValues(item.addressItem);
                    db.SaveChanges();

                    item.isMessageExist = true;
                    item.message = getSuccesMessage(lang.addressEditSuccess, "autoHide");
                    item.isSuccess = true;

                }
                catch (Exception ex)
                {
                    errorSend(ex, "Account Address Edit", true);
                    item.isMessageExist = true;
                    item.message = getErrorMessage(lang.unexpectedErrorMsg, "autoHide");
                }
            }

            string htmlText = RenderRazorViewToString("AddressEdit", item);
            return Json(new { html = htmlText });
        }
Пример #10
0
        public JsonResult AddressDelete(addressModelItem item)
        {
            System.Threading.Thread.Sleep(1500);

            //Close Url
            pageShared ps = new pageShared(db);
            addressShared ads = new addressShared(db);
            var mainPage = ps.getPageByType(pageType.account, langId);
            var addressPage = ps.getPageByType(pageType.accountAddress, langId);
            item.closeUrl = getSiteName(Request) + langCode + "/" + mainPage.url + "/" + addressPage.url + ".html";

            userShared us = new userShared(db);
            var userItem = us.getUserByGuid(item.guid);

            if (userItem == null || item.addressItem == null || item.addressItem.userId != userItem.userId)
            {
                item.isMessageExist = true;
                item.message = getErrorMessage(lang.unexpectedErrorMsg, "autoHide");

                return Json(new { html = RenderRazorViewToString("AddressEdit", item) }, JsonRequestBehavior.AllowGet);
            }

            try
            {

                ads.updateAddressIsDeleted(item.addressItem.addressId);
                item.isMessageExist = true;
                item.message = getSuccesMessage(lang.deleteAddressSuccess);
                item.isSuccess = true;

            }
            catch (Exception ex)
            {
                errorSend(ex, "Account Address Delete", true);
                item.isMessageExist = true;
                item.message = getErrorMessage(lang.unexpectedErrorMsg, "autoHide");
            }

            string htmlText = RenderRazorViewToString("AddressDelete", item);
            return Json(new { html = htmlText });
        }
Пример #11
0
        public JsonResult AddressDetail(string userGuid, int addressId)
        {
            userShared us = new userShared(db);
            addressShared ads = new addressShared(db);

            var userItem = us.getUserByGuid(userGuid);
            var addressItem = ads.getAddressById(addressId);

            addressModelItem item = new addressModelItem();

            if (userItem == null || addressItem == null || addressItem.userId != userItem.userId)
            {
                item.isMessageExist = true;
                item.message = getErrorMessage(lang.unexpectedErrorMsg);
            }

            item.addressItem = addressItem;

            return Json(new { html = RenderRazorViewToString("AddressDetail", item) }, JsonRequestBehavior.AllowGet);
        }
Пример #12
0
        public Tuple<bool, string> isDeliveryValid(titizOto.Models.titizOtoEntities db)
        {
            HelperSite.Shared.addressShared ads = new HelperSite.Shared.addressShared(db);

            // Unregistered User
            if (!cartItem.isRegisteredUser)
            {
                // Validate Track Info, name,surname,email
                var validateTrackInfo = ads.isValidTrackData(this.trackInfo);

                if (!validateTrackInfo.Item1)
                {
                    return validateTrackInfo;
                }

                // Validate Address
                var addressValidation = ads.isValidAddress(this.deliveryAddress);

                if (!addressValidation.Item1)
                {
                    return addressValidation;
                }

            }
            else  // Registered User
            {
                var addressItem = ads.getAddressById(this.deliveryAddressId);

                if (addressItem == null || addressItem.statu == false)
                {
                    return new Tuple<bool, string>(false, lang.checkoutDeliveryRequired);
                }

            }

            return new Tuple<bool, string>(true, null);
        }
Пример #13
0
        public Tuple<bool, string> isBillingValid(titizOto.Models.titizOtoEntities db)
        {
            HelperSite.Shared.addressShared ads = new HelperSite.Shared.addressShared(db);

            // Unregistered User
            if (!cartItem.isRegisteredUser)
            {
                // Validate Address
                var addressValidation = ads.isValidAddress(this.billingAddress);

                if (!addressValidation.Item1)
                {
                    return addressValidation;
                }
            }
            else
            {
                var addressItem = ads.getAddressById(this.billingAddressId);

                if (addressItem == null || addressItem.statu == false)
                {
                    return new Tuple<bool, string>(false, lang.checkoutDeliveryRequired);
                }

            }

            return new Tuple<bool, string>(true, null);
        }
Пример #14
0
        public JsonResult DeliveryRegisterModal(int pageId, int addressId)
        {
            checkoutProcess checkoutItem = (checkoutProcess)Session["checkoutProcess"];

            // Kayıtlı Üye
            if (checkoutItem.cartItem.isRegisteredUser)
            {
                addressShared ads = new addressShared(db);
                userShared us = new userShared(db);
                helperRegisterDelivery helperPage = new helperRegisterDelivery();

                sharedCheckoutItemLoad(pageId, helperPage, checkoutItem);

                helperPage.addressList = ads.getAddressListTemplate(checkoutItem.cartItem.userId).OrderByDescending(a => a.addressId).ToList();
                helperPage.userguid = checkoutItem.cartItem.userGuid;
                helperPage.selectedDeliveryAddressId = addressId;

                string htmlText = RenderRazorViewToString("DeliveryRegisterModal", helperPage);
                return Json(new { html = htmlText }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return null;
            }
        }
Пример #15
0
        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);
        }
Пример #16
0
        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);
        }
Пример #17
0
        internal orderInfo getOrderInfoByCheckoutProcess(checkoutProcess checkoutItem, orderSummary helperPage, DbWithControllerWithMaster helperController, BasketHtmlType htmlType, AddressHtmlType addressType, TransferHtmlType transferType, int langId)
        {
            var ads = new addressShared(db);
            var us = new userShared(db);
            var item = new ViewModel.Checkout.Summary.orderInfo();

            // Kayıtlı Üye
            if (checkoutItem.cartItem.isRegisteredUser)
            {

                //customerNameSurname
                item.customerNameSurname = checkoutItem.cartItem.nameSurname;

                //customerEmail
                var userId = checkoutItem.cartItem.userId;
                item.customerEmail = us.getUserById(userId).email;

                //customer Delivery Adress
                item.deliveryHtml = ads.getAddressHtml(checkoutItem.deliveryAddressId, addressType, helperController);

                //customerPhone
                item.customerPhone = ads.getAddresPhoneByAddressId(checkoutItem.deliveryAddressId);

                // customer Billing Addres
                item.billingHtml = ads.getAddressHtml(checkoutItem.billingAddressId, addressType, helperController);
            }
            else
            {
                //customerNameSurname
                item.customerNameSurname = checkoutItem.trackInfo.name + " " + checkoutItem.trackInfo.surname;

                //customerEmail
                item.customerEmail = checkoutItem.trackInfo.email;

                //customer Delivery Adress
                item.deliveryHtml = ads.getAddressHtml(checkoutItem.deliveryAddress, addressType, helperController);

                //customerPhone
                item.customerPhone = checkoutItem.deliveryAddress.phone;

                // customer Billing Addres
                item.billingHtml = ads.getAddressHtml(checkoutItem.billingAddress, addressType, helperController);
            }

            item.orderDate = DateTime.Now.ToString("dd.MM.yyyy");
            item.customerBasket = getBasketListWithPlainHtml(helperPage, helperController, htmlType);
            item.transferAccountHtml = getTransferInfoHtml(checkoutItem.transferInfo.selectedTransferId, langId, helperController, transferType);

            return item;
        }
Пример #18
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);
            }
        }