Example #1
0
        public void CreatePersonTest()
        {
            using (var context = new CoreContext())
            {
                var person = new Person {Age = 25};
                context.Entities.Add(person);
                context.SaveChanges();

                Assert.IsTrue(person.Id > 0);

                person = context.People.FirstOrDefault(x => x.Id == person.Id);
                Assert.IsNotNull(person);
            }
        }
Example #2
0
 public UserRepository(CoreContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #3
0
 public static CoreEntity GetEntityWithId(this CoreContext context, int value)
 {
     return(((Entitas.PrimaryEntityIndex <CoreEntity, int>)context.GetEntityIndex(Contexts.Id)).GetEntity(value));
 }
Example #4
0
 public RoleRepository(CoreContext context)
     : base(context)
 {
 }
 public AutoStatusChangeCommandHandler(CoreContext context)
 {
     _context = context;
 }
 public BaseDataAccess(CoreContext context)
 {
     _context = context;
     _entity  = context.Set <T>();
 }
    public UpdateFunSystem(Contexts contexts)
    {
        context = contexts.core;

        entities = context.GetGroup(CoreMatcher.AllOf(CoreMatcher.Flatmate, CoreMatcher.Fun, CoreMatcher.ActiveAction));
    }
Example #8
0
 public TaskService(CoreContext context, IUserProvider userProvider)
 {
     CaseNoteTasksService     = new CaseNoteTasksService(context);
     ReferralNoteTasksService = new ReferralNoteTasksService(context);
     UserProvider             = userProvider;
 }
Example #9
0
        //Must include a Configure method to create the app's request processing pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CoreContext dbContext)
        {
            ApplicationDbContext.EntityContext = () => dbContext;

            //How to pipeline works
            //app.Use(async (context, next) =>
            //{
            //    Console.WriteLine("Hello pipeline! {0}", context.Request.Path);
            //    await next();
            //});

            loggerFactory.AddConsole(); //Log To Console
            loggerFactory.AddDebug();   //Log To Output

            //For Log To File:
            //loggerFactory.AddProvider(new NLogLoggerProvider());
            //add NLog to ASP.NET Core
            //loggerFactory.AddNLog();
            //add NLog.Web
            //app.AddNLogWeb();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler();
            }

            //app.UseDefaultFiles();
            app.UseStaticFiles();     // For the wwwroot folder

            app.UseStatusCodePages(); //Middleware pipeline

            //attribute base for routing!
            app.UseMvc();//Middleware pipeline

            //app.UseMvc(config =>
            //{
            //    config.MapRoute(
            //        name: "Default",
            //        template: "{controller}/{action}/{id?}",
            //        defaults: new { controller = "App", action = "Index" },
            //        constraints: new { id = @"\d+" }
            //    );
            //});

            //app.Run((context) =>
            //{
            //    throw new Exception("new exception!");
            //});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RoleController"/> class.
 /// </summary>
 /// <param name="dbContext">The dbContext.</param>
 /// <param name="mapper">The mapper.</param>
 public RoleController(CoreContext dbContext, IMapper mapper) : base(dbContext, mapper)
 {
 }
Example #11
0
 public GJournalRepository(CoreContext context)
     : base(context)
 {
 }
Example #12
0
 public CoreGetByIdQuery(CoreContext context)
 {
     _context = context;
 }
Example #13
0
 /// <summary>
 /// Use to get controller's instance from context you passed as parameter.
 /// </summary>
 /// <param name="_coreContext">Type of controller from which you want to get instance</param>
 /// <returns>Return instance of specific controller</returns>
 public static T GetController <T>(CoreContext _coreContext) where T : UiCoreController <TUiPanelElement, TUiContext>
 {
     return(coreInstances[_coreContext] as T);
 }
Example #14
0
 public PrivilegeRepository(CoreContext context) : base(context)
 {
 }
Example #15
0
 public VideoRepository(CoreContext dbContext)
     : base(dbContext)
 {
 }
Example #16
0
 public GenericRepository(CoreContext context)
 {
     _context = context;
 }
Example #17
0
 public AppController(CoreContext context, ILogger <AppController> logger)
 {
     _logger           = logger;
     _context          = context;
     _pageDataServices = new PageDataServices(context, logger);
 }
Example #18
0
 public MedicalExamRepository(CoreContext context) : base(context)
 {
 }
Example #19
0
        protected override CommandResult <Hashtable> OnExecute(object commandParameter)
        {
            var result = new CommandResult <Hashtable>();
            var param  = commandParameter as DrawPrizeParameter;

            result.Data = new Hashtable();
            using (CoreContext context = new CoreContext())
            {
                var act = context.ActivityInfo.Where(a => a.StartTime <= DateTime.Now && a.EndTime >= DateTime.Now && a.Status == 1 && a.Kind == param.Kind).FirstOrDefault();
                if (act == null)
                {
                    result.ErrorCode    = -1;
                    result.ErrorMessage = "活动已结束";
                    return(result);
                }

                Hashtable pconfig = JsonConvert.DeserializeObject <Hashtable>(act.ProductConfig);

                var zlopenid = context.MemberInfo.Where(m => m.AccountId == param.MemberAccount).Select(m => m.ZlOpenId).FirstOrDefault();

                //扣减次数,使用数据库锁
                if (context.Database.ExecuteSqlCommand(@"update member_draw_count set current_count=(current_count-1) 
                                                        where member_account=@p0 and current_count-1>=0", zlopenid) > 0)
                {
                    var LogCount = context.ActivityLog.Where(l => l.MemberAccount == zlopenid && l.ActivityId == act.Recid).Count();
                    var res      = new NewMemberSkillCommand().Execute(new NewMemberSkillParameter()
                    {
                        MemberAccount = zlopenid,
                        LogCount      = LogCount,
                        Prize         = pconfig
                    });
                    Hashtable prize = null;
                    if (res.ErrorCode == 0 && (Convert.ToBoolean(res.Data["isNew"]) || Convert.ToBoolean(res.Data["is30"])))
                    {
                        result.ErrorCode    = res.ErrorCode;
                        result.ErrorMessage = res.ErrorMessage;
                        prize = res.Data["Prize"] as Hashtable;
                    }
                    else
                    {
                        var     connect = ConfigurationUtil.GetSection("ConnectionStrings")["ShopConnectString"];
                        decimal payFee  = 0;
                        using (MySqlConnection con = new MySqlConnection(connect))
                        {
                            con.Open();
                            MySqlCommand com1 = new MySqlCommand("select sum(payment_fee) as PayFee from shop_order_info " +
                                                                 "where member_account=?acc and pay_status=1 and order_no like '%00' and date(payment_time)>='2018-11-01' and date(payment_time)<='2018-11-11' ", con);
                            com1.Parameters.Add(new MySqlParameter("?acc", zlopenid));
                            var Reader1 = com1.ExecuteReader();
                            while (Reader1.Read())
                            {
                                if (Reader1["PayFee"] != DBNull.Value)
                                {
                                    payFee = Convert.ToDecimal(Reader1["PayFee"]);
                                }
                            }
                            Reader1.Close();
                            con.Close();
                        }
                        //遍历奖品规则
                        var redisdb = RedisClient.GetDatabase(1);
                        foreach (var item in (pconfig["PayPrize"] as JArray).ToObject <List <Hashtable> >())
                        {
                            JObject condiction = item["Condition"] as JObject;

                            string key = "level:" + condiction["Fee"].Value <string>();
                            if (redisdb.HashExists(key, param.MemberAccount))
                            {
                                continue;
                            }
                            if (payFee >= condiction["Fee"].Value <decimal>())
                            {
                                prize = (item["Prize"] as JObject).ToObject <Hashtable>();
                                //处理实物奖品
                                if (prize["Kind"] as string == "RealPrize")
                                {
                                    //var hash = (prize["RealPrize"] as JObject).ToObject<Hashtable>();
                                    var _realprize = new List <PrizeModel>();
                                    foreach (var hash in (prize["RealPrize"] as JArray).ToObject <List <Hashtable> >())
                                    {
                                        if (DateTime.Parse(hash["start"] as string) <= DateTime.Now && DateTime.Parse(hash["end"] as string) >= DateTime.Now)
                                        {
                                            _realprize.Add(new PrizeModel()
                                            {
                                                PrizeCode = hash["PrizeCode"] as string,
                                                PrizeName = hash["PrizeName"] as string,
                                                Kind      = prize["Kind"] as string
                                            });
                                        }
                                    }
                                    string RealPrize = "";

                                    if (_realprize.Count != 0)
                                    {
                                        var r     = new Random(Guid.NewGuid().GetHashCode());
                                        var index = r.Next(0, _realprize.Count);
                                        RealPrize = redisdb.ListLeftPop("Prize:" + _realprize[index].PrizeCode);
                                    }
                                    if (!string.IsNullOrEmpty(RealPrize))
                                    {
                                        prize = JsonConvert.DeserializeObject <Hashtable>(RealPrize);
                                    }
                                    else
                                    {
                                        prize = null;
                                    }
                                }
                                if (prize != null)
                                {
                                    redisdb.HashIncrementAsync(key, param.MemberAccount);
                                }
                                break;
                            }
                        }
                    }
                    if (prize != null)
                    {
                        result.Data = prize;
                        var p = new PrizeInfo()
                        {
                            Status        = 1,
                            ActId         = act.Recid,
                            CouponId      = Convert.ToInt32(prize["CouponId"]),
                            CreateDate    = DateTime.Now,
                            MemberAccount = zlopenid,
                            PrizeCode     = prize["PrizeCode"] as string,
                            PrizeName     = prize["PrizeName"] as string,
                            Kind          = prize["Kind"] as string,
                        };
                        context.PrizeInfo.Add(p);
                        if (prize["Kind"] as string == "Coupon")
                        {
                            //调用获取优惠券
                            var url = ConfigurationUtil.GetSection("CouponUrl").Value as string;
                            //领取抵扣优惠券
                            try
                            {
                                ActiveMQMessagePusher.Push("Command",
                                                           new Dictionary <string, string>
                                {
                                    { "caller", "Restful" },
                                    { "url", url }
                                }, new
                                {
                                    MemberAccount = zlopenid,
                                    RuleId        = Convert.ToInt32(prize["CouponId"])
                                }
                                                           );
                            }
                            catch (Exception)
                            {
                            }
                            //var couponres = ZlanAPICaller.Call<CommandResult<string>>(url, new { MemberAccount = zlopenid, RuleId = Convert.ToInt32(prize["CouponId"]) });
                            //if (couponres.ErrorCode == 0)
                            //{
                            //    couponticket = couponres.Data;
                            //}
                            //else
                            //{
                            //    LogUtil.Log("DrawPrize_TakeCoupon", p.Recid.ToString(), $"input=>{JsonConvert.SerializeObject(new { MemberAccount = zlopenid, RuleId = Convert.ToInt32(prize["CouponId"]) })}#error=>{res.ErrorMessage}");
                            //}
                        }
                    }
                    else
                    {
                        result.ErrorMessage = "未中奖,换个姿势再试试吧";
                        result.ErrorCode    = -22;
                    }
                }
                else
                {
                    result.ErrorCode    = -21;
                    result.ErrorMessage = "每下单68元,即获得一次抽奖机会,上不封顶";
                }
                context.ActivityLog.Add(new ActivityLog()
                {
                    MemberAccount = zlopenid,
                    ActivityId    = act.Recid,
                    CreateTime    = DateTime.Now,
                    Memo          = result.Data.Keys.Count > 0 ? "抽中:" + result.Data["PrizeName"] as string : result.ErrorMessage
                });
                context.SaveChanges();
            }

            return(result);
        }
Example #20
0
 protected override string GetAccount(CoreContext coreContext, string openeId)
 {
     return(coreContext.MemberInfo.Where(m => m.XcxOpenId == openeId).Select(m => m.AccountId).FirstOrDefault());
 }
Example #21
0
 public CoreEntityInsertCommand(CoreContext context)
 {
     _context = context;
     _dbset   = context.Set <TMdl>();
 }
Example #22
0
 public BaseRepository(CoreContext context)
 {
     _context = context;
 }
 public DurationTimeoutSystem(Contexts contexts)
 {
     this.context = contexts.core;
     this.command = contexts.command;
     timedObjects = context.GetGroup(CoreMatcher.AllOf(CoreMatcher.ActionDuration, CoreMatcher.FlatmateId));
 }
 public UpdateEnterRoomCleanlinessOpinionSystem(Contexts contexts) : base(contexts.core)
 {
     coreContext = contexts.core;
     flatmates   = coreContext.GetGroup(CoreMatcher.AllOf(CoreMatcher.FlatmateId));
 }
Example #25
0
 protected RepoBase()
 {
     Db    = new CoreContext();
     Table = Db.Set <T>();
 }
Example #26
0
 public SpecialtyRepository(CoreContext context)
     : base(context)
 {
 }
Example #27
0
 protected RepoBase(DbContextOptions <CoreContext> options)
 {
     Db    = new CoreContext(options);
     Table = Db.Set <T>();
 }
Example #28
0
 public LeaveGameCommandHandler(CoreContext context, IMediator mediator)
 {
     _context  = context;
     _mediator = mediator;
 }
Example #29
0
 public CategoryComand(CoreContext CoreContext)
 {
     _CoreContext = CoreContext;
 }
Example #30
0
 public CaseNotesService(CoreContext context) : base(SourceType.Case, context, new CaseNoteTasksService(context))
 {
 }
 public SimplePlaceholderRepository(CoreContext context) : base(context)
 {
 }