public async Task LogException(Exception ex) { try { LogModel log = new LogModel(); log.L_Title = ex.Message; log.L_Body = JsonConvert.SerializeObject(ex); log.L_FileName = ex.Source; await _logRepo.Insert(log); await _logRepo.CommitAllChanges(); } catch (Exception e) { await LogException(e); } }
public async Task <ActionResult> SetIndexSections(IndexSectionsModel ism) { try { IndexBoxInfoModel BoxInfo = ((List <IndexBoxInfoModel>)(await _indexboxinforepo.GetAll()).Data).FirstOrDefault(x => x.I_SecId == ism.Section && x.Lang == ism.Lang); if (BoxInfo == null) { await _indexboxinforepo.Insert(new IndexBoxInfoModel() { I_SecId = ism.Section, I_Title = ism.Title, I_Icon = ism.Icon, I_Sort = ism.Sort, Lang = ism.Lang }); await _indexboxinforepo.CommitAllChanges(); } else { await _indexboxinforepo.Update(new IndexBoxInfoModel() { I_Id = BoxInfo.I_Id, I_SecId = ism.Section, I_Title = ism.Title, I_Icon = ism.Icon, I_Sort = ism.Sort, Lang = ism.Lang }); await _indexboxinforepo.CommitAllChanges(); } List <IndexBoxProductRelModel> OldRelations = ((List <IndexBoxProductRelModel>)(await _indexsectionrepo.GetAll()).Data).Where(x => x.I_SecId == ism.Section && x.Lang == ism.Lang).ToList(); foreach (var item in OldRelations) { await _indexsectionrepo.Delete(item); } await _indexsectionrepo.CommitAllChanges(); foreach (int p in ism.Products) { await _indexsectionrepo.Insert(new IndexBoxProductRelModel() { Lang = ism.Lang, I_Pid = p, I_SecId = ism.Section }); } await _indexsectionrepo.CommitAllChanges(); return(new JsonResult(ResponseModel.Success("اطلاعات با موفقیت ذخیره گردید"))); } catch (Exception ex) { return(null); } }
public async Task <IActionResult> AddHeaderNotify(HeaderNotificationModel hnm) { try { return(new JsonResult(await _headernotifyrepo.Insert(hnm))); } catch (Exception ex) { return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }
public async Task <IActionResult> AddFaq(FaqModel hnm) { try { return(new JsonResult(await _faqrepo.Insert(hnm))); } catch (Exception ex) { return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }
public async Task <ActionResult> AddService(ServiceModel service) { try { return(new JsonResult(await _servicerepo.Insert(service))); } catch (Exception ex) { return(null); } }
public async Task <ActionResult> AddDepartment(DepartmentModel dp) { try { return(new JsonResult(await _departmentrepo.Insert(dp))); } catch (Exception ex) { return(null); } }
public async Task <IActionResult> AddTicket(TicketModel ticket) { try { return(new JsonResult(await _ticketrepo.Insert(ticket))); } catch (Exception ex) { _logger.LogError("", ex); return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }
public async Task <ActionResult> UpdateOption(OptionsModel om) { try { var option = ((List <OptionsModel>)(await _optionrepo.GetAll()).Data).FirstOrDefault(x => x.O_Key == om.O_Key); if (option == null) { return(new JsonResult(await _optionrepo.Insert(om))); } else { option.O_Value = om.O_Value; return(new JsonResult(await _optionrepo.Update(option))); } } catch (Exception ex) { _logger.LogError("Error in options controller", ex); return(new JsonResult(ResponseModel.Error(data: ex))); } }
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)); } }