Exemplo n.º 1
0
        /// <summary>
        /// 创建订阅者
        /// </summary>
        /// <returns></returns>
        public ActionResult CreateSubscribe()
        {
            var model = new RedisSubscriber();

            model.Id = TDemoTable.GetNewId().ToString();
            return(View(model));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 单个字段修改
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ActionResult> EditMany()
        {
            /////修改的属性集合
            //var fieldList = new List<UpdateDefinition<TDemoTable>>();

            //fieldList.Add(Builders<TDemoTable>.Update.Set(item => item.F_String, "单条个修改"));

            //if (fieldList.Count > 0)
            //{
            //    var builders = Builders<TDemoTable>.Update.Combine(fieldList);
            //    await db.TDemoTable().UpdateOneAsync(item => item.Id == 904616499, builders);
            //}

            var model = new TDemoTable();

            model.F_DateTime = DateTime.Now;
            model.F_Bool     = true;
            model.F_Float    = 0.01f;
            model.F_Int      = 0;
            model.F_BoolNull = true;
            model.CreateTime = DateTime.Now;
            model.F_Guid     = Guid.NewGuid().ToString();
            model.F_String   = "只修改该字段";
            model.Id         = 904616499;
            await db.TDemoTable().UpdateOneAsync(item => item.Id == model.Id, () => new TDemoTable {
                F_Int = 55555
            });

            return(Json(new { state = true, value = "批量编辑成功" }));
        }
Exemplo n.º 3
0
        public async Task <JsonResult> Edit(TDemoTable model, string userId)
        {
            if (!this.TryValidateModel(model))
            {
                return(Json(new { state = false, value = this.ModelState.FirstModelErrorMessage() }));
            }
            var state = await PubSubRedis.Instance.UpdateOrAddRedisAsync(userId, model);

            return(Json(new { state = state, value = "编辑成功" }));
        }
Exemplo n.º 4
0
        public async Task <JsonResult> Create(TDemoTable model)
        {
            model.F_Guid = Guid.NewGuid().ToString();
            using (var db = new MysqlDb())
            {
                db.TDemoTable.Add(model);
                await db.SaveChangesAsync();

                return(Json(new { state = true, value = "操作成功" }));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 保存数据库
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private async Task Add(TDemoTable model)
        {
            using (var db = new SqlDb())
            {
                db.TDemoTable.Add(model);
                await db.SaveChangesAsync();

                MessageBox.Show(JsonSerializer.Serialize(model));
                await InitializeData();
            }
        }
Exemplo n.º 6
0
        public ActionResult Create()
        {
            var model = new TDemoTable();

            model.F_DateTime = DateTime.Now;
            model.F_Bool     = true;
            model.F_Float    = 0.01f;
            model.F_Int      = TDemoTable.GetNewId();
            model.F_BoolNull = true;
            model.CreateTime = DateTime.Now;
            return(View("Create", model));
        }
Exemplo n.º 7
0
        public async Task <JsonResult> Create(TDemoTable model, string UserId)
        {
            var user = await PubSubRedis.Instance.FindSubscribeAsync(UserId);

            if (user == null)
            {
                return(Json(new { state = false, value = "操作失败" }));
            }
            model.F_Guid     = Guid.NewGuid().ToString();
            model.CreateTime = DateTime.Now;
            var state = await PubSubRedis.Instance.Publish(DataAction.Add, model, UserId);

            return(Json(new { state = state > 0, value = "操作成功" }));
        }
Exemplo n.º 8
0
        public async Task <JsonResult> Edit(TDemoTable model)
        {
            if (!this.TryValidateModel(model))
            {
                return(Json(new { state = false, value = this.ModelState.FirstModelErrorMessage() }));
            }

            await db.TDemoTable().UpdateOneAsync(item => item.Id == model.Id, model);

            //指定指定修改
            //await db.TDemoTable().UpdateOneAsync(item => item.Id == model.Id, () => new TDemoTable { F_Int = 55555 });

            return(Json(new { state = true, value = "编辑成功" }));
        }
Exemplo n.º 9
0
        public async Task <JsonResult> Edit(TDemoTable model)
        {
            if (!this.TryValidateModel(model))
            {
                return(Json(new { state = false, value = this.ModelState.FirstModelErrorMessage() }));
            }

            using (var db = new MysqlDb())
            {
                db.Entry(model).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(Json(new { state = true, value = "编辑成功" }));
            }
        }
Exemplo n.º 10
0
        public async Task <JsonResult> Create(TDemoTable model)
        {
            model.F_Guid     = Guid.NewGuid().ToString();
            model.CreateTime = DateTime.Now;
            SqlDb.inter.Add(model);
            await SqlDb.inter.SaveChangesAsync();

            return(Json(new { state = true, value = "操作成功" }));
            ////using (var db = new SqlDb())
            ////{
            ////    db.TDemoTable.Add(model);
            ////    await db.SaveChangesAsync();

            ////    return Json(new { state = true, value = "操作成功" });
            ////}
        }
Exemplo n.º 11
0
 /// <summary>
 /// 创建测试模型
 /// </summary>
 /// <returns></returns>
 public static TDemoTable GetDemoModel()
 {
     var now = DateTime.Now;
     var model = new TDemoTable()
     {
         F_Guid = Guid.NewGuid().ToString(),
         F_Bool = true,
         F_DateTime = now,
         F_Float = 0.01f,
         Id = GetNewId(),
         F_Int = 1,
         F_IntNull = -1,
         F_String = "String",
         CreateTime = now
     };
     return model;
 }
Exemplo n.º 12
0
        public async Task <ActionResult> Create()
        {
            var model = new TDemoTable();

            model.F_DateTime = DateTime.Now;
            model.F_Bool     = true;
            model.F_Float    = 0.01f;
            model.F_Int      = 0;
            model.F_BoolNull = true;
            model.CreateTime = DateTime.Now;
            model.Id         = TDemoTable.GetNewId();

            var userlist = await PubSubRedis.Instance.GetAllSubscribeAsync();

            ViewBag.UserList = userlist.Select(item => new SelectListItem()
            {
                Text = item.Name, Value = item.Id
            });
            return(View(model));
        }
Exemplo n.º 13
0
        /// <summary>
        /// 保存单条记录
        /// 如记录不存在,新增
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="TDemoTable">保实实体</param>
        /// <param name="notify">是否扒</param>
        /// <returns></returns>
        public async Task <bool> UpdateOrAddRedisAsync(string userId, TDemoTable model, bool notify = true)
        {
            model.F_Guid = string.IsNullOrEmpty(model.F_Guid) ? Guid.NewGuid().ToString() : model.F_Guid;
            var data = new RedisSyncData()
            {
                ChangeID   = model.F_Guid,
                TypeName   = model.GetType().Name,
                ChangeTime = DateTime.Now,
                Action     = DataAction.Update,
                Data       = model
            };

            await this.AddToRedisAsync(new[] { userId }, new[] { data });

            if (notify)
            {
                await this.TryNotify(new[] { userId });
            }
            return(true);
        }
Exemplo n.º 14
0
        public async Task <JsonResult> CreateRange(int Count)
        {
            var list = new List <TDemoTable>();

            for (int i = 0; i < Count; i++)
            {
                var model = new TDemoTable();
                model.F_DateTime = DateTime.Now;
                model.F_Bool     = true;
                model.F_Float    = 0.01f;
                model.F_Int      = 0;
                model.F_BoolNull = true;
                model.CreateTime = DateTime.Now;
                model.F_Guid     = Guid.NewGuid().ToString();
                model.Id         = model.F_Guid.GetHashCode();
                list.Add(model);
            }
            await db.TDemoTable().AddRangeAsync(list);

            return(Json(new { state = true, value = "批量成功添加 " + Count + "条记录." }));
        }
Exemplo n.º 15
0
 /// <summary>
 /// 保存年数据库
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 private async Task AddYear(TDemoTable model)
 {
     await new MongoDbBase().TDemoTableYear(DateTime.Now).AddAsync(model);
     MessageBox.Show(JsonSerializer.Serialize(model));
     await InitializeDataYear();
 }
Exemplo n.º 16
0
        public async Task <JsonResult> Create(TDemoTable model)
        {
            await db.TDemoTable().AddAsync(model);

            return(Json(new { state = true, value = "操作成功" }));
        }