public async Task <IActionResult> OnPostAsync(CancellationToken CancellationToken)
        {
            DisCount disCount = new DisCount
            {
                Id              = Model.Id,
                Count           = Model.Count,
                DisCountPercent = Model.DisCountPercent,
                MaxDate         = Model.MaxDate.ToGregorian(),
                StartDate       = Model.StartDate.ToGregorian(),
                Title           = Model.Title
            };

            await disCountRepository.UpdateAsync(disCount, CancellationToken);

            return(RedirectToPage("/Admin/DisCountManagement/Index"));
        }
        public async Task <JsonResult> Pay(string DisCountTitle, string OrderId, CancellationToken cancellationToken)
        {
            AjaxResult     result   = new AjaxResult("Error");
            PayInput       input    = new PayInput();
            PaymentRequest response = new PaymentRequest();
            CustomUser     user     = new CustomUser();
            DisCount       DisCount = new DisCount();

            if (string.IsNullOrEmpty(OrderId))
            {
                result.Errors.Add("اطلاعات ارسالی صحیح نیس");
                return(new JsonResult(result));
            }

            Order order = await orderRepository.GetByIdAsync(Guid.Parse(OrderId), cancellationToken);

            if (order == null)
            {
                result.Errors.Add("اطلاعات ارسالی صحیح نیس");
                return(new JsonResult(result));
            }

            input.Deposits = order.TotalPrice;

            if (!string.IsNullOrEmpty(DisCountTitle))
            {
                DisCount = await disCountRepository.GetByTitle(DisCountTitle.Trim(), cancellationToken);

                input.Deposits = DisCount != null?DisCountHelper.ComputeDisCount(DisCount, order.TotalPrice) : order.TotalPrice;
            }

            if (User.Identity.IsAuthenticated)
            {
                user = await customUserManager.GetUserAsync(User);
            }
            else
            {
                string anonymousUserId = cookieManager.Get <string>("LocalhostCart");

                user = await orderRepository.GetAnonymousUser(anonymousUserId, cancellationToken);
            }

            input.Deposits = DisCountHelper.WithdrawFromWallet(user, input.Deposits);

            input.PhoneNumber = user?.PhoneNumber;

            if (input.Deposits >= 1000)
            {
                input.Redirect    = siteSetting.BuyCourseCallBackUrl;
                input.Description = "تصویه صورت حساب با احتساب تخفیف و کسر از کیف پولتان";
                response          = await payment.PayAsync(input, cancellationToken);
            }
            else
            {
                result.Status               = "Success";
                result.RedirectUrl          = "";
                result.MessageWhenSuccessed = " مبلغ با محاسبه تخفیف و کسر از کیف پول پرداخت شد";
                DisCount.Count              = DisCount.Count > 0 ? --DisCount.Count : DisCount.Count;
                await customUserManager.UpdateAsync(user);

                order.IsBought = true;
                await disCountRepository.UpdateAsync(DisCount, cancellationToken);

                return(new JsonResult(result));
            }
            if (Assert.NotNull(response) && response.Status == 1 && Assert.NotNull(response.Token))
            {
                result.Status      = "Success";
                result.RedirectUrl = siteSetting.RedirectUrl + response.Token;
                user.PaymentToken  = response.Token;
                DisCount.Count     = DisCount.Count > 0 ? DisCount.Count-- : DisCount.Count;
                await customUserManager.UpdateAsync(user);

                order.IsBought = true;
                await disCountRepository.UpdateAsync(DisCount, cancellationToken);

                return(new JsonResult(result));
            }
            else
            {
                result.Errors.Add("عملیات پرداخت با شکست مواجه شد لطفا بعدا امتحان کنید");
                result.Errors.Add(response.ErrorMessage);
            }

            return(new JsonResult(result));
        }