当前位置: 首页>>代码示例>>C#>>正文


C# ExpandoObject.AddProp方法代码示例

本文整理汇总了C#中System.Dynamic.ExpandoObject.AddProp方法的典型用法代码示例。如果您正苦于以下问题:C# ExpandoObject.AddProp方法的具体用法?C# ExpandoObject.AddProp怎么用?C# ExpandoObject.AddProp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Dynamic.ExpandoObject的用法示例。


在下文中一共展示了ExpandoObject.AddProp方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PplByDay

        public async Task<IHttpActionResult> PplByDay()
        {
            collection = mongoDb.GetCollection<object>("movement");

            var userId = User.Identity.GetUserId();

            var user = await userManager.FindByIdAsync(userId);

            var channel = user.Channels.FirstOrDefault(x => x.ChannelId.Equals(3) && x.UserId.Equals(userId));

            if (channel != null)
            {
                List<MovementModelExtended> data = null;

                if (channel.Price > 0)
                {
                    var result = (await collection.FindAsync<MovementModelExtended>(new BsonDocument(), new FindOptions<object, MovementModelExtended>
                    {
                        //Limit = (int)channel.MaxPayedRows
                    }));

                    data = await result.ToListAsync();
                }

                else
                    data = await (await collection.FindAsync<MovementModelExtended>(new BsonDocument("UserId", userId))).ToListAsync();

                List<object> response = new List<object>();

                for (int i = 1; i <= 24; i++)
                {
                    int count = 0;
                    var obj = new ExpandoObject();

                    foreach (var date in data)
                    {
                        if (i.Equals(date.Created.Hour))
                        {
                            count += 1;
                            if (((IDictionary<string, object>)obj).ContainsKey("date"))
                            {
                                ((IDictionary<string, object>)obj)["date"] = date.Created;
                            }
                            else
                            {
                                obj.AddProp("date", date.Created);
                            }
                        }
                    }
                    var dict = ((IDictionary<string, object>)obj);

                    if (dict.ContainsKey("date"))
                    {
                        obj.AddProp("hour", ((DateTime)dict["date"]).Hour);
                        obj.AddProp("count", count);

                        response.Add(obj);
                    }
                }

                return Ok(new ApiResponse(200, response.ToArray()));
            }
            else
            {
                return this.NotFound(new ApiResponse(404));
            }
        }
开发者ID:dmacan23,项目名称:FireBreathingRubberDuckies---Sensei,代码行数:67,代码来源:ChannelApiController.cs

示例2: Movement

        public async Task<IHttpActionResult> Movement(MovementApiModel model)
        {
            if (ModelState.IsValid && model != null)
            {
                collection = mongoDb.GetCollection<object>("movement");

                var userId = (await db.Devices.FirstAsync(x => x.UniqueId.Equals(model.DeviceId))).UserId;

                var mapped = Mapper.Map<MovementModel>(model);
                mapped.Created = DateTime.Now;
                mapped.UserId = userId;

                var bson = BsonSerializer.Deserialize<ExpandoObject>(BsonDocument.Parse(JsonConvert.SerializeObject(mapped)));

                await collection.InsertOneAsync(bson);

                List<object> response = new List<object>();

                var channel = await db.Channels.FirstAsync(x => x.ChannelId.Equals(3) && x.UserId.Equals(userId));

                List<MovementModelExtended> data = null;

                if (channel.Price > 0)
                {
                    var result = (await collection.FindAsync<MovementModelExtended>(new BsonDocument(), new FindOptions<object, MovementModelExtended>
                    {
                        //Limit = (int)channel.MaxPayedRows
                    }));

                    data = await result.ToListAsync();
                }

                else
                    data = await (await collection.FindAsync<MovementModelExtended>(new BsonDocument("UserId", userId))).ToListAsync();

                for (int i = 1; i <= 24; i++)
                {
                    int count = 0;
                    var obj = new ExpandoObject();

                    foreach (var date in data)
                    {
                        if (i.Equals(date.Created.Hour))
                        {
                            count += 1;
                            if (((IDictionary<string, object>)obj).ContainsKey("date"))
                            {
                                ((IDictionary<string, object>)obj)["date"] = date.Created;
                            }
                            else
                            {
                                obj.AddProp("date", date.Created);
                            }
                        }
                    }
                    var dict = ((IDictionary<string, object>)obj);

                    if (dict.ContainsKey("date"))
                    {
                        obj.AddProp("hour", ((DateTime)dict["date"]).Hour);
                        obj.AddProp("count", count);

                        response.Add(obj);
                    }
                }

                NotificationHub.GetHubContext().Clients.All.movement(new ApiResponse(200, response.ToArray()));

                return Ok(new ApiResponse(200, mapped));
            }

            return this.BadRequest(new ApiResponse(400));
        }
开发者ID:dmacan23,项目名称:FireBreathingRubberDuckies---Sensei,代码行数:73,代码来源:ChannelApiController.cs

示例3: FridgeByDate

        public async Task<IHttpActionResult> FridgeByDate()
        {
            collection = mongoDb.GetCollection<object>("fridge");

            var userId = User.Identity.GetUserId();

            var user = await userManager.FindByIdAsync(userId);

            var channel = await db.Channels.FirstOrDefaultAsync(x => x.ChannelId.Equals(2) && x.UserId.Equals(userId));

            if (channel != null)
            {
                List<FridgeModelExtended> data = null;

                if (channel.Price > 0)
                {
                    var result = (await collection.FindAsync<FridgeModelExtended>(new BsonDocument(), new FindOptions<object, FridgeModelExtended>
                    {
                        //Limit = (int)channel.MaxPayedRows
                    }));

                    data = await result.ToListAsync();
                }

                else
                    data = await (await collection.FindAsync<FridgeModelExtended>(new BsonDocument("UserId", UserId))).ToListAsync();

                List<object> response = new List<object>();

                var distinct = data.Select(x => x.Created.ToShortDateString()).Distinct();

                foreach (var date in distinct)
                {
                    int count = 0;
                    var obj = new ExpandoObject();

                    foreach (var item in data)
                    {
                        if (item.Created.ToShortDateString().Equals(date))
                            count += 1;
                    }

                    obj.AddProp("count", count);
                    obj.AddProp("date", DateTime.Parse(date));

                    response.Add(obj);
                }

                return Ok(new ApiResponse(200, response.ToArray()));
            }
            else
            {
                return this.NotFound(new ApiResponse(404));
            }
        }
开发者ID:dmacan23,项目名称:FireBreathingRubberDuckies---Sensei,代码行数:55,代码来源:ChannelApiController.cs

示例4: Fridge

        public async Task<IHttpActionResult> Fridge(FridgeApiModel model)
        {
            if (ModelState.IsValid && model != null)
            {
                collection = mongoDb.GetCollection<object>("fridge");

                var userId = (await db.Devices.FirstAsync(x => x.UniqueId.Equals(model.DeviceId))).UserId;

                var mapped = Mapper.Map<FridgeModel>(model);
                mapped.Created = DateTime.Now;
                mapped.UserId = userId;

                var bson = BsonSerializer.Deserialize<ExpandoObject>(BsonDocument.Parse(JsonConvert.SerializeObject(mapped)));

                await collection.InsertOneAsync(bson);

                List<object> response = new List<object>();

                var channel = await db.Channels.FirstAsync(x => x.ChannelId.Equals(2) && x.UserId.Equals(userId));

                List<FridgeModelExtended> data = null;

                if (channel.Price > 0)
                {
                    var result = (await collection.FindAsync<FridgeModelExtended>(new BsonDocument(), new FindOptions<object, FridgeModelExtended>
                    {
                        //Limit = (int)channel.MaxPayedRows
                    }));

                    data = await result.ToListAsync();
                }

                else
                    try
                    {
                        data = await (await collection.FindAsync<FridgeModelExtended>(new BsonDocument("UserId", userId))).ToListAsync();
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.Message);
                    }

                if (data != null)
                {
                    var distinct = data.Select(x => x.Created.ToShortDateString()).Distinct();

                    foreach (var date in distinct)
                    {
                        int count = 0;
                        var obj = new ExpandoObject();

                        foreach (var item in data)
                        {
                            if (item.Created.ToShortDateString().Equals(date))
                                count += 1;
                        }

                        obj.AddProp("count", count);
                        obj.AddProp("date", DateTime.Parse(date));

                        response.Add(obj);
                    }

                    NotificationHub.GetHubContext().Clients.All.fridge(new ApiResponse(200, response.ToArray()));

                    return Ok(new ApiResponse(200, mapped));
                }
                else
                {
                    return this.NotFound(new ApiResponse(404));
                }
            }

            return this.BadRequest(new ApiResponse(400));
        }
开发者ID:dmacan23,项目名称:FireBreathingRubberDuckies---Sensei,代码行数:75,代码来源:ChannelApiController.cs


注:本文中的System.Dynamic.ExpandoObject.AddProp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。