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


C# Delta.TrySetPropertyValue方法代码示例

本文整理汇总了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));
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:19,代码来源:ProductsV1Controller.cs

示例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);
		}
开发者ID:WorkMarketingNet,项目名称:WMN.Companies,代码行数:21,代码来源:CompaniesControllerTests.cs

示例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);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:15,代码来源:ComplexTypeInheritanceControllers.cs

示例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);
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:7,代码来源:ContainmentControllers.cs

示例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;
            }
        }
开发者ID:trichards57,项目名称:new-bike-tracker,代码行数:40,代码来源:IMEIControllerTests.cs


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