本文整理汇总了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));
}
}
示例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));
}
示例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));
}
}
示例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));
}