Exemplo n.º 1
0
        public async Task <IActionResult> Index([FromServices] TengoDbContext db, PageInfo pageInfo, DateTime?datemin = null, DateTime?datemax = null, string keyword = null)
        {
            ViewBag.Keyword = keyword;
            ViewBag.datemin = ((DateTime)datemin).ToString("yyyy-MM-dd");
            ViewBag.datemax = ((DateTime)datemax).ToString("yyyy-MM-dd");

            var query = db.SMSLog.AsQueryable();

            if (!string.IsNullOrWhiteSpace(keyword))
            {
                query = query.Where(p => p.Mobile.Contains(keyword) ||
                                    p.Content.Contains(keyword) ||
                                    p.SendFor.Contains(keyword) ||
                                    p.Platform.Contains(keyword));
            }

            if (datemin > new DateTime(1900, 1, 1))
            {
                query = query.Where(p => p.AddTime >= datemin);
            }

            if (datemax > new DateTime(1900, 1, 1))
            {
                var end = ((DateTime)datemax).AddDays(1);
                query = query.Where(p => p.AddTime <= end);
            }

            ViewData.Model = await db.GetPageListAsync(query, pageInfo);

            return(View());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index([FromServices] TengoDbContext db, PageInfo pageInfo, List <int> categoryID = null, string keyword = null, string sortBy = null)
        {
            ViewBag.Keyword    = keyword;
            ViewBag.CategoryId = categoryID;
            ViewBag.Category   = await db.Category.ToListAsync();

            ViewBag.Goods = await service.PageList(pageInfo, categoryID, keyword, sortBy);

            return(View());
        }
Exemplo n.º 3
0
 /// <summary>
 /// 测试联表并筛选自定义Model
 /// </summary>
 /// <param name="db"></param>
 public void TestUnion([FromServices] TengoDbContext db)
 {
     var query = from Address addr in db.Address.AsQueryable()
                 join user in db.User.AsQueryable()
                 on addr.UserID equals user.Id
                 where 1 == 1
                 select new {
         user.Id,
         user.NickName,
         addr.Province
     };
     var data = query.ToList();
 }
Exemplo n.º 4
0
        public async Task <IActionResult> Index([FromServices] TengoDbContext db)
        {
            ViewBag.Banners = await db.Article
                              .Where(p => p.ArticleType.TypeName == "首页轮播图")
                              .OrderByDescending(p => p.Id)
                              .Take(10)
                              .ToListAsync();

            ViewBag.Goods = await db.Goods.Where(p => p.Status == 1)
                            .OrderByDescending(p => p.Id)
                            .Take(10)
                            .ToListAsync();

            return(View());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Edit([FromServices] TengoDbContext db, int id = 0)
        {
            if (id <= 0)
            {
                return(new NotFoundResult());
            }
            var model = await db.Article.FirstOrDefaultAsync(p => p.Id == id);

            if (model == null)
            {
                return(new NotFoundResult());
            }
            ViewData.Model = model;
            return(View());
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit([FromServices] TengoDbContext db, int id = 0)
        {
            if (id <= 0)
            {
                return(new NotFoundResult());;
            }
            var model = await db.Article.FirstOrDefaultAsync(p => p.Id == id);

            ViewData.Model = model;
            if (model == null)
            {
                return(new NotFoundResult());
            }
            ViewBag.ArticleTypeId = new SelectList(await service.ArticleTypeList(), "Id", "TypeName", model.ArticleTypeId);
            return(View());
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Edit([FromServices] TengoDbContext db, int id = 0)
        {
            if (id <= 0)
            {
                return(new NotFoundResult());
            }
            var model = await service.Get(id);

            ViewData.Model = model;
            if (model == null)
            {
                return(new NotFoundResult());
            }
            ViewBag.Category = await db.Category.ToListAsync();

            return(View());
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Index([FromServices] TengoDbContext db, PageInfo pageInfo, int articleTypeId = 0, string keyword = null, string sortBy = null)
        {
            var query = db.Article.AsQueryable();

            if (articleTypeId > 0)
            {
                query = query.Where(p => p.ArticleTypeId == articleTypeId);
            }
            if (!string.IsNullOrWhiteSpace(keyword))
            {
                keyword = keyword.Trim();
                query   = query.Where(p => p.Title.Contains(keyword));
            }
            ViewData.Model = await db.GetPageListAsync(query, pageInfo.Page, pageInfo.PageSize);

            ViewBag.Keyword        = keyword;
            ViewBag.ArticleTypeId  = articleTypeId;
            ViewBag.ArticleTypeIds = new SelectList(await service.ArticleTypeList(), "Id", "TypeName", articleTypeId);
            return(View());
        }
Exemplo n.º 9
0
        public async Task <IActionResult> GetEditData([FromServices] TengoDbContext db)
        {
            var cartList = new List <object>();

            foreach (var item in db.CartItem.Include(p => p.Goods))
            {
                cartList.Add(new {
                    item.Goods.Id,
                    item.Goods.Name,
                    item.Goods.NameEn,
                    item.Goods.Price,
                    item.Goods.CoverImg,
                    item.Qty
                });
            }
            ;

            var addrList = await db.Address.Where(p => p.UserID == 1).ToListAsync();

            return(MyJsonResultSuccess("success", new {
                cartList,
                addrList
            }));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> List([FromServices] TengoDbContext db, PageInfo pageInfo)
        {
            var list = await db.GetPageListAsync(db.Order.Include(p => p.GoodsList).Where(p => p.UserID == 1), pageInfo);

            return(MyJsonResultSuccess("s", list));
        }
Exemplo n.º 11
0
 public ArticleBLL(TengoDbContext db) : base(db)
 {
 }
Exemplo n.º 12
0
 public OrderBLL(TengoDbContext db) : base(db)
 {
 }
Exemplo n.º 13
0
 public AddressBLL(TengoDbContext db) : base(db)
 {
 }
Exemplo n.º 14
0
 public CategoryBLL(TengoDbContext db) : base(db)
 {
 }
Exemplo n.º 15
0
        public async Task <IActionResult> Add([FromServices] TengoDbContext db)
        {
            ViewBag.Category = await db.Category.ToListAsync();

            return(View());
        }
Exemplo n.º 16
0
        public async Task <ActionResult> WXPay([FromServices] TengoDbContext db
                                               , int outTradeNo = 0, string code = null, int orderId = 0, int isDelaySend = 0)
        {
            //如果outTradeNo参数为空,那么是第一次进来的情况
            if (outTradeNo <= 0)
            {
                #region  商场本身业务逻辑 第一次(也就是从订单点击去支付之后)进来的时候会执行这里
                if (orderId <= 0)
                {
                    return(Redirect("/error"));
                }
                var order = await db.Order.FirstOrDefaultAsync(p => p.Id == orderId);

                if (order == null)
                {
                    return(Redirect("/error"));
                }
                if (order.RealAmount == 0)  //如果支付金额是0元,那么有可能是活动啥的不用付钱,那么状态应该是已经支付了的,直接跳回去看看
                {
                    return(Redirect("/order/detail?id=" + order.Id));
                }
                if (order.PayStatus)
                {
                    return(Redirect("/order/detail?id=" + order.Id));
                }

                #endregion

                #region 构造网页授权获取code的URL,并且重定向跳转到微信的地址
                var host = HttpContext.Request.Host;
                var path = Request.Path;
                //指定获取code之后要跳回来的地址,这里我会加上订单流水号
                var redirect_uri = HttpUtility.UrlEncode("https://" + host + "/payment/WXPay?outTradeNo=" + orderId);
                var data         = new WxPayData();
                data.SetValue("appid", WxPayConfig.APPID);
                data.SetValue("redirect_uri", redirect_uri);
                data.SetValue("response_type", "code");
                data.SetValue("scope", "snsapi_base");
                data.SetValue("state", "STATE" + "#wechat_redirect");
                var url = "https://open.weixin.qq.com/connect/oauth2/authorize?" + data.ToUrl();
                //触发微信返回code码
                return(Redirect(url));//Redirect函数会抛出ThreadAbortException异常,不用处理这个异常

                #endregion
            }
            //重定向回来之后包含了code
            else if (!string.IsNullOrWhiteSpace(code))
            {
                #region GetOpenidAndAccessToken 从Url里面拿取上面第一步重定向之后返回来附带的code,然后进一步获取openid和accessToken,接着再统一下单,获取支付参数

                var model = new WXPay();

                #region  GetOpenidAndAccessTokenFromCode(code); 先通过code构造请求来获取openid和accessToken
                try {
                    //构造获取openid及access_token的url
                    var data = new WxPayData();
                    data.SetValue("appid", WxPayConfig.APPID);
                    data.SetValue("secret", WxPayConfig.APPSECRET);
                    //写入code码,以获取openid和access_token
                    data.SetValue("code", code);
                    data.SetValue("grant_type", "authorization_code");
                    string url = "https://api.weixin.qq.com/sns/oauth2/access_token?" + data.ToUrl();

                    //请求url以获取数据
                    string result = HttpService.Get(url);

                    //LogFactory.GetLogger().Info("WXPay", "GetOpenidAndAccessTokenFromCode响应 : " + result);

                    //保存access_token,用于收货地址获取
                    var jd = JsonMapper.ToObject(result);
                    model.access_token = (string)jd["access_token"];

                    //获取用户openid
                    model.openid = (string)jd["openid"];

                    //LogFactory.GetLogger().Info("WXPay", "获取到的openid : " + model.openid);
                    //LogFactory.GetLogger().Info("WXPay", "获取到的access_token : " + model.access_token);
                }
                catch (Exception ex) {
                    //LogFactory.GetLogger().Error("WXPay", ex, remark: "GetOpenidAndAccessTokenFromCode错误");
                    throw new WxPayException(ex.ToString());
                }
                #endregion

                try {
                    //读取订单信息
                    var order = await db.Order.FirstOrDefaultAsync(p => p.Id == outTradeNo);

                    //注意这里的订单号就要设置为流水号了
                    model.out_trade_no = outTradeNo.ToString();
                    model.total_fee    = Convert.ToInt32(order.RealAmount * 100);

                    #region 调用统一下单,获得下单结果 获取prepay_id
                    //统一下单
                    var data = new WxPayData();

                    #region 处理商品前缀
                    var subject = "Teogn电商商品";
                    #endregion

                    data.SetValue("body", subject);   //商品描述
                    data.SetValue("attach", subject); //附加数据

                    data.SetValue("out_trade_no", model.out_trade_no);
                    data.SetValue("total_fee", model.total_fee);

                    data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
                    data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
                    data.SetValue("goods_tag", "");//订单优惠标记
                    data.SetValue("trade_type", "JSAPI");
                    data.SetValue("openid", model.openid);

                    var unifiedOrderResult = WxPayApi.UnifiedOrder(data);
                    if (!unifiedOrderResult.IsSet("appid") || !unifiedOrderResult.IsSet("prepay_id") || unifiedOrderResult.GetValue("prepay_id").ToString() == "")
                    {
                        //LogFactory.GetLogger().Info("WXPay", "统一下单报错:UnifiedOrder response error!");
                        throw new WxPayException("UnifiedOrder response error!");
                    }


                    #endregion

                    #region  获取H5调起JS API参数
                    //LogFactory.GetLogger().Info("WXPay", "JsApiPay::GetJsApiParam is processing...");
                    var jsApiParam = new WxPayData();
                    jsApiParam.SetValue("appId", unifiedOrderResult.GetValue("appid"));
                    jsApiParam.SetValue("timeStamp", WxPayApi.GenerateTimeStamp());
                    jsApiParam.SetValue("nonceStr", WxPayApi.GenerateNonceStr());
                    jsApiParam.SetValue("package", "prepay_id=" + unifiedOrderResult.GetValue("prepay_id"));
                    jsApiParam.SetValue("signType", "MD5");
                    jsApiParam.SetValue("paySign", jsApiParam.MakeSign());
                    model.wxJsApiParam = jsApiParam.ToJson();
                    //LogFactory.GetLogger().Info("WXPay", "wxJsApiParam : " + model.wxJsApiParam);
                    #endregion

                    ViewData.Model = model;
                    return(View());
                }
                catch (Exception exp) {
                    //LogFactory.GetLogger().Error("微信支付异常", exp);
                    return(Redirect("/error?msg=微信支付异常..."));
                }
                #endregion
            }
            else  //异常情况,不用理会
            {
                return(Redirect("/error?msg=支付异常..."));
            }
        }
Exemplo n.º 17
0
 public CartBLL(TengoDbContext db) : base(db)
 {
 }
Exemplo n.º 18
0
 public BaseBLL(TengoDbContext db)
 {
     this.db = db;
 }
Exemplo n.º 19
0
 public ColumnController(TengoDbContext db)
 {
     this.db = db;
 }
Exemplo n.º 20
0
 public ColumnTypeController(TengoDbContext db, ColumnTypeBLL bll)
 {
     this.db  = db;
     this.bll = bll;
 }
Exemplo n.º 21
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            #region MVC服务模块设置
            //到3.0版本后不再需要在此处引入Mvc 2.0
            //services.AddMvc();

            //添加了对控制器和 API 相关功能的支持,但不支持视图或页面 3.0
            //services.AddControllers();

            //添加了对 Razor 页面和最小控制器支持的支持 3.0
            //services.AddRazorPages();

            //添加了对控制器、API 相关功能和视图(而不是页)的支持。 3.0
            //services.AddControllersWithViews(); + services.AddRazorPages() = 2.2版本的 services.AddMvc();
            services.AddControllersWithViews();
            #endregion

            #region Cookie
            //这个方法用于注入一个默认的Cookie策略配置,配置Cookie的共通属性
            services.Configure <CookiePolicyOptions>(options =>
            {
                /*
                 * This lambda determines whether user consent for non-essential cookies is needed for a given request.
                 * 此lambda确定给定请求是否需要非必需cookie的用户同意。
                 * 我的解释:ASP.NET CORE支持欧洲常规数据保护法规 (GDPR),即在客户端存储Cookie需要经过用户的同意。
                 * 当然,是有办法跳过的,我们可以设置下面这个lambda,全局指定存储Cookie是否一定要经过用户同意。
                 * 如果是True的话,那么要经过用户同意才能存;false则不管你同意不同意,都存。
                 */
                options.CheckConsentNeeded    = context => false;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
            #endregion

            #region Cache缓存服务

            /*
             * 添加Microsoft.Extensions.Caching.Distributed.IDistributedCache的默认实现
             * 将内存中的项存储到Microsoft.Extensions.DependencyInjection.IServiceCollection。
             * 需要分布式缓存才能工作的框架可以安全地添加此依赖项作为其依赖项列表的一部分,以确保至少有一个实现可用。
             *
             * 个人理解:框架现在不会自动给我们把缓存的模块开启了,因此需要我们自己手动开启。
             *           cache也是Session以及缓存的基础,没有缓存的话,根本就没办法存储这些数据了。
             *           默认的缓存设置是将缓存存在本机内存中。可以指定特定的缓存提供者而不是用内存来存储,后面再弄下。
             */
            services.AddDistributedMemoryCache();
            #endregion

            #region Session
            //添加应用程序会话状态所需的服务。
            services.AddSession(options =>
            {
                // Set a short timeout for easy testing.
                //设置Session的有效时间
                options.IdleTimeout = TimeSpan.FromSeconds(120);
                //指定SessionId的Cookie只能由服务端通过HTTP请求修改设置。
                options.Cookie.HttpOnly = true;
                // Make the session cookie essential
                //使Session以Cookie为基础
                options.Cookie.IsEssential = true;
            });
            #endregion

            #region 数据库
            //初始化数据库配置
            var connection = Configuration.GetConnectionString("DefaultConnectionString");
            TengoDbContext.Init(services, connection);
            #endregion

            #region DI与IOC服务
            //注册执行我自己编写的依赖注入方法
            services.UseTengoDI();
            #region 自己注册的依赖注入【已废弃】,因为我编写了新的能够根据类名结尾来批量依赖注入的类
            //配置依赖注入的两种写法,后者代码简洁一些
            //services.AddScoped(typeof(IUserService), typeof(UserService));
            //services.AddScoped<IUserService, UserService>();
            //services.AddScoped<ArticleBLL>();
            #endregion
            #endregion

            ///配置自定义视图查询器,让框架能够根据设备类型来适配不同的视图
            //services.Configure<RazorViewEngineOptions>(o => {
            //    o.ViewLocationExpanders.Add(new CustomViewLocationExpander());
            //});
        }
Exemplo n.º 22
0
        public async Task <IActionResult> Index([FromServices] TengoDbContext db)
        {
            ViewData.Model = await db.Category.ToListAsync();

            return(View());
        }
Exemplo n.º 23
0
 public SmsBLL(TengoDbContext db, ISMS smsSender) : base(db)
 {
     this.smsSender = smsSender;
 }
Exemplo n.º 24
0
 public ArticlesController(TengoDbContext context)
 {
     _context = context;
 }
Exemplo n.º 25
0
 public UserBLL(TengoDbContext db) : base(db)
 {
 }
Exemplo n.º 26
0
 public ColumnTypeBLL(TengoDbContext db) : base(db)
 {
 }
Exemplo n.º 27
0
 public GoodsBLL(TengoDbContext db) : base(db)
 {
 }