public async Task <IActionResult> ConfirmUser(string mobile) { if (!string.IsNullOrEmpty(mobile)) { string rnd = UtilesService.RandomDigit(5); await _sms.Otp(mobile, rnd); TempData["rnd"] = rnd; TempData["mobile"] = mobile; return(View()); } return(RedirectToAction("Index", "Home")); }
public async Task <ResponseStructure> Insert(NoticesModel entity) { try { entity.N_Date = UtilesService.PersianToMiladi(entity.N_ShamsiDate); await this._context.Notices.AddAsync(entity : entity); await this.CommitAllChanges(); return(ResponseModel.Success("operation successfully completed")); } catch (Exception ex) { return(null); } }
public async Task <ResponseStructure> TestCheckout(HttpRequest httpRequest, HttpResponse httpResponse, int type = 1, bool RequestedPOS = false) { try { var authorize = Barayand.Common.Services.TokenService.AuthorizeUser(httpRequest); if (authorize < 1) { return(ResponseModel.Error("کاربر وارد نشده است")); } UserModel userModel = await _userrepository.GetById(authorize); if (userModel == null) { return(ResponseModel.Error("کاربر یافت نشد")); } FullPropertyBasketModel BasketModel = new FullPropertyBasketModel(); string cookie; string InvoiceID = null; if (httpRequest.Cookies.TryGetValue("Cart", out cookie)) { if (cookie != null) { var basketInfo = Barayand.Common.Services.CryptoJsService.DecryptStringAES(cookie); BasketModel = JsonConvert.DeserializeObject <FullPropertyBasketModel>(basketInfo); if (BasketModel.CartItems.Count() > 0) { BasketViewModel basketView = await GetBasketItems(httpRequest); InvoiceModel Invoice = new InvoiceModel(); Invoice.I_BoxWrapperId = BasketModel.GiftBoxWrapperId; Invoice.I_CopponDiscount = (BasketModel.Coppon.Count() > 0) ? BasketModel.Coppon.Sum(x => x.CP_Discount) : 0; Invoice.I_CopponId = (BasketModel.Coppon.Count() > 0) ? BasketModel.Coppon.FirstOrDefault().CP_Id : 0; Invoice.I_DeliveryDate = BasketModel.RecipientInfo.DeliveryDate; Invoice.I_PaymentDate = DateTime.Now; Invoice.I_PaymentInfo = "Test payment"; Invoice.I_PaymentType = type; Invoice.I_RecipientInfo = JsonConvert.SerializeObject(BasketModel.RecipientInfo); Invoice.I_RequestedPOS = RequestedPOS; Invoice.I_Status = 2; Invoice.I_TotalProductAmount = basketView.Products.Sum(x => x.Total); Invoice.I_TotalAmount = basketView.Total; Invoice.I_UserId = userModel.U_Id; Invoice.I_Id = UtilesService.RandomDigit(12); var insertInvoiceResult = await _invoicerepository.Insert(Invoice); if (insertInvoiceResult.Status == false) { return(insertInvoiceResult); } int AvailAbleCounts = 0; foreach (var item in BasketModel.CartItems) { OrderModel order = new OrderModel(); if (item.ProductType == 1) { var combine = await _productcombinerepo.GetById(item.ProductCombineId); if (combine != null && combine.X_AvailableCount >= item.Quantity) { AvailAbleCounts++; order.O_ColorId = combine.X_ColorId; order.O_ProductId = combine.X_ProductId; order.O_WarrantyId = combine.X_WarrantyId; order.O_ReciptId = Invoice.I_Id; order.O_Quantity = item.Quantity; order.O_ProductType = 1; order.O_Price = combine.PriceModel.Price; order.O_Discount = combine.PriceModel.HasDiscount ? combine.PriceModel.Discount : 0; order.O_DiscountType = 1; order.O_GiftId = item.GiftProductCombineId; await _orderrepository.Insert(order); } } else { var pmanual = await _productmanualrepo.GetById(item.ProductCombineId); if (pmanual != null) { AvailAbleCounts++; order.O_ProductId = pmanual.M_ProductId; order.O_ReciptId = Invoice.I_Id; order.O_Quantity = item.Quantity; order.O_ProductType = 2; order.O_Price = pmanual.M_Price; await _orderrepository.Insert(order); } } } InvoiceID = Invoice.I_Id; if (AvailAbleCounts < 1) { await _invoicerepository.Delete(InvoiceID); await FreeUpCart(httpRequest, httpResponse); return(ResponseModel.Error("تمامی کالاهای موجود در سبد خرید شما ناموجود میباشند")); } } } } await FreeUpCart(httpRequest, httpResponse); return(ResponseModel.Success("سفارش شما با موفقیت ثبت گردید", data: InvoiceID)); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ResponseStructure> TestCheckout(HttpRequest httpRequest, HttpResponse httpResponse, int type = 1) { try { var authorize = Barayand.Common.Services.TokenService.AuthorizeUser(httpRequest); if (authorize < 1) { return(ResponseModel.Error("User not logged in.")); } var basket = await GetBasketItems(httpRequest); if (basket.CartItems.Count < 1) { return(ResponseModel.Error("Basket is empty.")); } UserModel userModel = await _userrepository.GetById(authorize); decimal wll = userModel.U_Wallet; decimal Sum = basket.BasketTotalAmount(_lang.GetLang(), CVRT); InvoiceModel invoice = new InvoiceModel(); invoice.I_TotalAmount = basket.BasketTotalAmount(_lang.GetLang(), CVRT); invoice.I_Id = UtilesService.RandomDigit(12); invoice.I_UserId = authorize; invoice.I_ShippingCost = basket.ShippingCost; invoice.I_RecipientInfo = JsonConvert.SerializeObject(basket.RecipientInfo); invoice.I_CopponDiscount = basket.SumDiscount(); invoice.I_CopponId = (basket.Coppon.Count > 0) ? basket.Coppon.FirstOrDefault().CP_Id : 0; invoice.Created_At = DateTime.Now; invoice.I_PaymentDate = DateTime.Now; invoice.I_TotalProductAmount = basket.BasketTotalProductPrice(_lang.GetLang(), CVRT); invoice.I_PaymentInfo = "Test payment"; invoice.I_PaymentType = type; if (type == 2) { decimal w = (_lang.GetLang() == "fa") ?userModel.U_Wallet : userModel.U_Wallet / CVRT; if (w < basket.BasketTotalAmount(_lang.GetLang(), CVRT)) { return(ResponseModel.Error("موجودی کیف پول شما کافی نمیباشد")); } else { w = w - basket.BasketTotalAmount(_lang.GetLang(), CVRT); await _walletrepository.DecreaseWallet(userModel.U_Id, basket.BasketTotalAmount("fa", CVRT)); await _smsService.WalletAllert(userModel.U_Phone, 2, basket.BasketTotalAmount(_lang.GetLang(), CVRT).ToString("#,# تومان")); invoice.I_Status = 2; } } if (type == 3) { decimal w = userModel.U_Coupon; if (w < basket.BasketProductBinPriceTotal(BINPERC)) { return(ResponseModel.Error("تعداد بن های شما برای پرداخت کافی نمیباشد")); } else { userModel.U_Coupon = userModel.U_Coupon - basket.BasketProductBinPriceTotal(BINPERC); await _userrepository.Update(userModel); invoice.I_Status = 2; } } if (type == 4) { invoice.I_Status = 1; } if (type == 1) { invoice.I_Status = 2; } ResponseStructure res = await _invoicerepository.Insert(invoice); if (!res.Status) { return(res); } int sumGiftBon = basket.BasketProductBinPriceTotal(BINPERC); foreach (var item in basket.CartItems) { //sumGiftBon += (item.Product.P_GiftBin * item.Quantity); var orderres = await _orderrepository.Insert(new OrderModel() { O_Discount = (!item.PrintAble) ? basket.BasketProductPrice(item.Product.P_Id, _lang.GetLang(), false, false) : basket.BasketProductPrintablePrice(item.Product.P_Id, _lang.GetLang(), false, false), O_DiscountType = item.Product.P_DiscountType, O_Price = (!item.PrintAble) ? basket.BasketProductPrice(item.Product.P_Id, _lang.GetLang(), true, false) : basket.BasketProductPrintablePrice(item.Product.P_Id, _lang.GetLang(), true, false), O_Quantity = item.Quantity, O_ProductId = item.Product.P_Id, O_ReciptId = invoice.I_Id, Created_At = DateTime.Now, Lang = _lang.GetLang(), O_Version = item.PrintAble ? 2 : 1 }); } userModel.U_Coupon += sumGiftBon; await _userrepository.Update(userModel); await this.FreeUpCart(httpRequest, httpResponse); if (_lang.GetLang() == "fa") { await _smsService.OrderAlert(userModel.U_Phone, invoice.I_Id, basket.BasketTotalAmount(_lang.GetLang(), CVRT).ToString("#,# تومان")); } return(ResponseModel.Success("سفارش شما با موفقیت ثبت گردید", new { invoiceid = invoice.I_Id })); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }