本文整理汇总了C#中System.Web.OData.Delta.TrySetPropertyValue方法的典型用法代码示例。如果您正苦于以下问题:C# Delta.TrySetPropertyValue方法的具体用法?C# Delta.TrySetPropertyValue怎么用?C# Delta.TrySetPropertyValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.OData.Delta
的用法示例。
在下文中一共展示了Delta.TrySetPropertyValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Patch
public IHttpActionResult Patch([FromODataUri] int key, Delta<Product> patch)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
Delta<V2VM.Product> v2Patch = new Delta<V2VM.Product>();
foreach (string name in patch.GetChangedPropertyNames())
{
object value;
if (patch.TryGetPropertyValue(name, out value))
{
v2Patch.TrySetPropertyValue(name, value);
}
}
var v2Product = _repository.Patch((long)key, v2Patch, Request);
return Updated(Mapper.Map<Product>(v2Product));
}
示例2: CompaniesController_Patch_WhenICallPatch
public async Task CompaniesController_Patch_WhenICallPatch()
{
// Given
var companiesController = _container.Resolve<CompaniesController>();
// When
const int id = 2;
var delta = new Delta<TranslatedCompany>();
delta.TrySetPropertyValue("Logo", Guid.NewGuid().ToString());
delta.TrySetPropertyValue("Headquarters", Guid.NewGuid().ToString());
var updateResult = await companiesController.Patch(id, delta) as UpdatedODataResult<TranslatedCompany>;
// Then
Assert.NotNull(updateResult);
Assert.NotNull(updateResult.Entity);
var company = delta.GetEntity();
Assert.Equal(id, updateResult.Entity.Id);
Assert.Equal(company.Logo, updateResult.Entity.Logo);
Assert.Equal(company.Headquarters, updateResult.Entity.Headquarters);
}
示例3: Patch
public IHttpActionResult Patch(int key, Delta<Window> delta)
{
delta.TrySetPropertyValue("Id", key); // It is the key property, and should not be updated.
Window window = _windows.FirstOrDefault(e => e.Id == key);
if (window == null)
{
window = new Window();
delta.Patch(window);
return Created(window);
}
delta.Patch(window);
return Ok(window);
}
示例4: PatchPremiumAccount
public IHttpActionResult PatchPremiumAccount(int key, Delta<PremiumAccount> delta)
{
var originalAccount = _dataSource.Accounts.Single(a => a.AccountID == key) as PremiumAccount;
delta.TrySetPropertyValue("AccountID", originalAccount.AccountID); // It is the key property, and should not be updated.
delta.Patch(originalAccount);
return Ok(originalAccount);
}
示例5: PutIMEIToCallsign
private async Task PutIMEIToCallsign(int id, string callsign, string imei, VehicleType? type, ResultType expectedResult = ResultType.Success)
{
var logService = CreateMockLogService();
var service = CreateMockIMEIService();
var controller = new IMEIController(service.Object, logService.Object);
var config = new Mock<HttpConfiguration>();
var principal = MockHelpers.CreateMockPrincipal(TestUsername);
controller.User = principal.Object;
controller.Configuration = config.Object;
var delta = new Delta<IMEIToCallsign>();
if (!string.IsNullOrEmpty(imei))
delta.TrySetPropertyValue("IMEI", imei);
if (!string.IsNullOrEmpty(callsign))
delta.TrySetPropertyValue("CallSign", callsign);
if (type != null)
delta.TrySetPropertyValue("Type", type);
var res = await controller.Put(id, delta);
switch (expectedResult)
{
case ResultType.ModelError:
Assert.IsType<InvalidModelStateResult>(res);
logService.Verify(l => l.LogIMEIRegistered(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<VehicleType>()), Times.Never);
break;
case ResultType.NotFoundError:
Assert.IsType<NotFoundResult>(res);
logService.Verify(l => l.LogIMEIRegistered(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<VehicleType>()), Times.Never);
break;
case ResultType.Success:
Assert.IsType<UpdatedODataResult<IMEIToCallsign>>(res);
service.Verify(i => i.RegisterCallsign(imei, callsign, type));
logService.Verify(l => l.LogIMEIRegistered(TestUsername, imei, callsign, type ?? VehicleType.Unknown));
break;
}
}