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 }); }
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); }
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); }
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); }
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); }
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); } }