本文整理汇总了C#中System.Web.HttpContextBase.GetOrDeserializeRequestStreamJson方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContextBase.GetOrDeserializeRequestStreamJson方法的具体用法?C# HttpContextBase.GetOrDeserializeRequestStreamJson怎么用?C# HttpContextBase.GetOrDeserializeRequestStreamJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpContextBase
的用法示例。
在下文中一共展示了HttpContextBase.GetOrDeserializeRequestStreamJson方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
private void Update(HttpContextBase context)
{
var item = Selection.ParseSelectionFromRequest();
if (item == null)
throw new HttpException((int)HttpStatusCode.NotFound, "Not Found");
var requestBody = context.GetOrDeserializeRequestStreamJson<object>();
foreach (var kvp in requestBody)
item[kvp.Key] = kvp.Value;
engine.Persister.Save(item);
}
示例2: Create
private void Create(HttpContextBase context)
{
var parent = Selection.ParseSelectionFromRequest();
if (parent == null)
throw new HttpException((int)HttpStatusCode.NotFound, "Not Found");
var discriminator = context.Request["discriminator"];
var definition = engine.Definitions.GetDefinition(discriminator);
var item = engine.Resolve<ContentActivator>().CreateInstance(definition.ItemType, parent);
var requestBody = context.GetOrDeserializeRequestStreamJson<object>();
foreach (var kvp in requestBody)
item[kvp.Key] = kvp.Value;
engine.Persister.Save(item);
}
示例3: Patch
private void Patch(HttpContextBase context)
{
var requestBody = context.GetOrDeserializeRequestStreamJson<object>();
var user = GetUser(context.User);
if (requestBody.ContainsKey("Settings") && requestBody["Settings"] is IDictionary<string, object>)
foreach (var kvp in (IDictionary<string, object>)requestBody["Settings"])
{
if (kvp.Value != null)
user.Settings[kvp.Key] = kvp.Value;
else
user.Settings.Remove(kvp.Key);
}
repository.Save(user);
context.Response.WriteJson(new { User = user });
}