コード例 #1
0
        public IActionResult Add()
        {
            HttpRequestChecker.RequieAjaxRequest();
            var request         = HttpManager.CurrentContext.Request;
            var productId       = request.Get <long>("productId");
            var matchParameters = request.Get <ProductMatchParameters>("matchParameters");
            var isBuyNow        = request.Get <bool>("isBuyNow");
            var cartProductType = isBuyNow ? CartProductType.Buynow : CartProductType.Default;
            // 添加购物车商品,抛出无权限错误时跳转到登陆页面
            var cartProductManager = Application.Ioc.Resolve <CartProductManager>();

            try {
                cartProductManager.AddCartProduct(productId, cartProductType, matchParameters);
            } catch (HttpException ex) {
                if (ex.StatusCode == 403)
                {
                    return(new JsonResult(new { redirectTo = "/user/login" }));
                }
                throw;
            }
            // 立刻购买时跳转到购物车页面
            if (isBuyNow)
            {
                return(new JsonResult(new { redirectTo = "/cart?type=buynow" }));
            }
            // 加入购物车时显示弹出框,包含商品总数和价格
            var currencyManager = Application.Ioc.Resolve <CurrencyManager>();
            var totalCount      = cartProductManager.GetCartProductTotalCount(cartProductType);
            var totalPrices     = cartProductManager.GetCartProductTotalPrice(
                cartProductManager.GetCartProducts(cartProductType));
            var totalPriceString = string.Join(", ", totalPrices.Select(
                                                   pair => currencyManager.GetCurrency(pair.Key).Format(pair.Value)));

            return(new JsonResult(new { showDialog = new { totalCount, totalPriceString } }));
        }
コード例 #2
0
        public IActionResult UpdateCounts()
        {
            HttpRequestChecker.RequieAjaxRequest();
            var counts             = HttpManager.CurrentContext.Request.Get <IDictionary <long, long> >("counts");
            var cartProductManager = Application.Ioc.Resolve <CartProductManager>();

            cartProductManager.UpdateCartProductCounts(counts);
            return(new JsonResult(new { }));
        }
コード例 #3
0
        public IActionResult Delete()
        {
            HttpRequestChecker.RequieAjaxRequest();
            var id = HttpManager.CurrentContext.Request.Get <long>("id");
            var cartProductManager = Application.Ioc.Resolve <CartProductManager>();

            cartProductManager.DeleteCartProduct(id);
            return(new JsonResult(new { message = new T("Delete Successfully") }));
        }
コード例 #4
0
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <returns></returns>
        public virtual IActionResult UploadAction()
        {
            // 检查权限
            HttpRequestChecker.RequieAjaxRequest();
            var privilegeManager = Application.Ioc.Resolve <PrivilegeManager>();

            privilegeManager.Check(AllowedUserTypes, RequiredPrivileges);
            // 返回上传结果
            var form = GetForm();

            return(new JsonResult(form.Submit()));
        }
コード例 #5
0
        /// <summary>
        /// 批量操作请求的处理函数
        /// </summary>
        /// <returns></returns>
        protected virtual IActionResult BatchAction()
        {
            HttpRequestChecker.RequieAjaxRequest();
            var request    = HttpManager.CurrentContext.Request;
            var actionName = request.Get <string>("action");
            var action     = BatchActions.GetOrDefault(actionName);

            if (action == null)
            {
                // 找不到对应的操作
                throw new NotFoundException(string.Format(new T("Action {0} not exist"), actionName));
            }
            return(action());
        }
コード例 #6
0
        /// <summary>
        /// 删除图片
        /// </summary>
        /// <returns></returns>
        public virtual IActionResult RemoveAction()
        {
            // 检查权限
            HttpRequestChecker.RequieAjaxRequest();
            var privilegeManager = Application.Ioc.Resolve <PrivilegeManager>();

            privilegeManager.Check(AllowedUserTypes, RequiredPrivileges);
            // 返回删除结果
            var imageManager = Application.Ioc.Resolve <ImageManager>();
            var name         = HttpManager.CurrentContext.Request.Get <string>("name");

            imageManager.Remove(CategoryLower, name);
            return(new JsonResult(new { message = new T("Remove Successfully") }));
        }
コード例 #7
0
        public IActionResult Create()
        {
            HttpRequestChecker.RequieAjaxRequest();
            var orderManager          = Application.Ioc.Resolve <OrderManager>();
            var transactionManager    = Application.Ioc.Resolve <PaymentTransactionManager>();
            var sessionManager        = Application.Ioc.Resolve <SessionManager>();
            var createOrderParameters = HttpManager.CurrentContext.Request
                                        .Get <CreateOrderParameters>("CreateOrderParameters") ?? new CreateOrderParameters();

            createOrderParameters.SetLoginInfo();
            var result      = orderManager.CreateOrder(createOrderParameters);
            var transaction = result.CreatedTransactions.Last();
            var paymentUrl  = transactionManager.GetPaymentUrl(transaction.Id);

            return(new JsonResult(new { script = ScriptStrings.Redirect(paymentUrl) }));
        }
コード例 #8
0
        public IActionResult CalculatePrice()
        {
            HttpRequestChecker.RequieAjaxRequest();
            var createOrderParameters = HttpManager.CurrentContext.Request
                                        .Get <CreateOrderParameters>("CreateOrderParameters") ?? new CreateOrderParameters();

            createOrderParameters.SetLoginInfo();
            var cartProductManager = Application.Ioc.Resolve <CartProductManager>();

            try {
                var info = cartProductManager.GetCartCalculatePriceApiInfo(createOrderParameters);
                return(new JsonResult(new { priceInfo = info }));
            } catch (Exception ex) {
                return(new JsonResult(new { error = ex.Message }));
            }
        }
コード例 #9
0
        /// <summary>
        /// 删除翻译内容
        /// </summary>
        /// <returns></returns>
        protected virtual IActionResult DeleteAction()
        {
            // 检查权限
            HttpRequestChecker.RequieAjaxRequest();
            var privilegeManager = Application.Ioc.Resolve <PrivilegeManager>();

            privilegeManager.Check(AllowedUserTypes, RequiredPrivileges);
            // 获取参数并执行删除
            var json     = HttpManager.CurrentContext.Request.Get <string>("json");
            var original = JsonConvert.DeserializeObject <IList <string> >(json).FirstOrDefault();

            if (!string.IsNullOrEmpty(original))
            {
                Translates.Remove(original);
            }
            Translates = Translates;
            return(new JsonResult(new { message = new T("Delete Successful") }));
        }
コード例 #10
0
        /// <summary>
        /// 处理POST请求
        /// </summary>
        /// <returns></returns>
        protected virtual IActionResult PostAction()
        {
            HttpRequestChecker.RequieAjaxRequest();
            var request          = HttpManager.CurrentContext.Request;
            var action           = request.Get <string>("action");
            var webTesterManager = Application.Ioc.Resolve <WebTesterManager>();

            if (action == "fetch")
            {
                // 抓取测试信息
                var lastUpdateds = request.Get <Dictionary <string, string> >("lastUpdateds") ??
                                   new Dictionary <string, string>();
                var informations = webTesterManager.GetInformations(lastUpdateds);
                return(new JsonResult(new { informations }));
            }
            else if (action == "reset_all")
            {
                // 重置测试结果
                webTesterManager.ResetInformations();
                return(new JsonResult(new { message = new T("Request submitted, wait processing") }));
            }
            else if (action == "start_all")
            {
                // 开始全部测试
                webTesterManager.RunAllAssemblyTestBackground();
                return(new JsonResult(new { message = new T("Request submitted, wait processing") }));
            }
            else if (action == "start")
            {
                // 开始单项测试
                var assemblyName = request.Get <string>("assembly");
                webTesterManager.RunAssemblyTestBackground(assemblyName);
                return(new JsonResult(new { message = new T("Request submitted, wait processing") }));
            }
            throw new ArgumentException(string.Format("unknown action {0}", action));
        }