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


C# Delta.Patch方法代码示例

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


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

示例1: Patch

        public IHttpActionResult Patch([FromODataUri] int key, Delta<Product> patch)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Product product = db.Products.Find(key);
            if (product == null)
            {
                return NotFound();
            }

            patch.Patch(product);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return Updated(product);
        }
开发者ID:aadiswan,项目名称:mytest,代码行数:33,代码来源:ProductsController.cs

示例2: Patch

        public IHttpActionResult Patch([FromODataUri] int key, Delta<Admin> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Admin admin = db.Admin.Find(key);
            if (admin == null)
            {
                return NotFound();
            }

            patch.Patch(admin);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdminExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return Updated(admin);
        }
开发者ID:Nasri-Bilel,项目名称:SMART-CITY-IS,代码行数:35,代码来源:AdminsController.cs

示例3: Patch

        public IHttpActionResult Patch([FromODataUri] string key, Delta<AspNetRole> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            AspNetRole aspNetRole = db.AspNetRoles.Find(key);
            if (aspNetRole == null)
            {
                return NotFound();
            }

            patch.Patch(aspNetRole);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AspNetRoleExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return Updated(aspNetRole);
        }
开发者ID:GeraldBecker,项目名称:WindowsDefender,代码行数:35,代码来源:ODAspNetRolesController.cs

示例4: Patch

        public IHttpActionResult Patch([FromODataUri] int key, Delta<MatchHistory> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            MatchHistory matchHistory = db.MatchHistories.Find(key);
            if (matchHistory == null)
            {
                return NotFound();
            }

            patch.Patch(matchHistory);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MatchHistoryExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return Updated(matchHistory);
        }
开发者ID:GeraldBecker,项目名称:WindowsDefender,代码行数:35,代码来源:MatchHistoriesController.cs

示例5: Patch

        public IHttpActionResult Patch([FromODataUri] int key, Delta<Order> patch)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Order order = db.Orders.Find(key);
            if (order == null)
            {
                return NotFound();
            }

            patch.Patch(order);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return Updated(order);
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:33,代码来源:OrdersController.cs

示例6: Patch

        public IHttpActionResult Patch(Delta<SampleModel> delta)
        {
            // Using the Patch method on Delta<T>, will only overwrite only the properties whose value has
            // changed.
            var model = new SampleModel();
            delta.Patch(model);

            // Using Delta doesn't invoke validation on the values that are provided, so use the Validate method
            // on the model object after patching to validate it.
            this.Validate(model);
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var builder = new StringBuilder();
            builder.AppendLine("Updated Properties:");

            foreach(var property in delta.GetChangedPropertyNames())
            {
                object value;
                delta.TryGetPropertyValue(property, out value);

                builder.AppendLine(String.Format("\t{0} : {1}", property, value));
            }

            return Text(builder.ToString());
        }
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:28,代码来源:PatchController.cs

示例7: Patch

        public IHttpActionResult Patch([FromODataUri] int key, Delta<Customer> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Customer customer = db.Customers.Find(key);
            if (customer == null)
            {
                return NotFound();
            }

            patch.Patch(customer);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return Updated(customer);
        }
开发者ID:CriticalPathTraining,项目名称:GOA365,代码行数:35,代码来源:Customers1Controller.cs

示例8: Patch

        public IHttpActionResult Patch([FromODataUri] int key, Delta<UserTask> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            UserTask userTask = db.Tasks.Find(key);
            if (userTask == null)
            {
                return NotFound();
            }

            patch.Patch(userTask);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserTaskExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return Updated(userTask);
        }
开发者ID:Senfer,项目名称:FinalITRCP,代码行数:35,代码来源:UserTasksController.cs

示例9: Patch

        public Item Patch(int id, Delta<Item> newItem)
        {
            var item = _items.FirstOrDefault(x => x.Id == id);
            if (item == null) throw new HttpResponseException(HttpStatusCode.NotFound);

            newItem.Patch(item);

            return item;
        }
开发者ID:diouf,项目名称:apress-recipes-webapi,代码行数:9,代码来源:TestController.cs

示例10: Patch

        public TestItemType Patch([FromODataUri] int key, Delta<TestItemType> patch)
        {
            TestItemType testitemtype = db.TestItemTypes.Find(key);
            patch.Patch(testitemtype);

            db.SaveChanges();

            return testitemtype;
        }
开发者ID:BredStik,项目名称:jaydata,代码行数:9,代码来源:TestItemTypesController.cs

示例11: PatchPerson

        public HttpResponseMessage PatchPerson([FromODataUri] string firstName, [FromODataUri] string lastName, Delta<Person> delta)
        {
            var person = _repo.Get(firstName, lastName);
            if (person == null)
            {
                return Request.CreateResponse(HttpStatusCode.NotFound);
            }
            delta.Patch(person);
            person.FirstName = firstName;
            person.LastName = lastName;
            _repo.UpdateOrAdd(person);

            return Request.CreateResponse(HttpStatusCode.OK);
        }
开发者ID:srihari-sridharan,项目名称:Programming-Playground,代码行数:14,代码来源:PeopleController.cs

示例12: PatchPerson

        public IHttpActionResult PatchPerson([FromODataUri] string firstName, [FromODataUri] string lastName, Delta<Person> delta)
        {
            var person = _repo.Get(firstName, lastName);
            if (person == null)
            {
                return NotFound();
            }

            delta.Patch(person);

            person.FirstName = firstName;
            person.LastName = lastName;
            _repo.UpdateOrAdd(person);

            return Updated(person);
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:16,代码来源:PeopleController.cs

示例13: CanPatch

        public void CanPatch()
        {
            var original = new AddressEntity { ID = 1, City = "Redmond", State = "WA", StreetAddress = "21110 NE 44th St", ZipCode = 98074 };

            dynamic delta = new Delta<AddressEntity>();
            delta.City = "Sammamish";
            delta.StreetAddress = "23213 NE 15th Ct";

            delta.Patch(original);
            // unchanged
            Assert.Equal(1, original.ID);
            Assert.Equal(98074, original.ZipCode);
            Assert.Equal("WA", original.State);
            // changed
            Assert.Equal("Sammamish", original.City);
            Assert.Equal("23213 NE 15th Ct", original.StreetAddress);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:17,代码来源:DeltaTest.cs

示例14: Patch

 public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<Customer> patch)
 {
     object id;
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     else if (patch.TryGetPropertyValue("Id", out id) && (int)id != key)
     {
         return BadRequest("The key from the url must match the key of the entity in the body");
     }
     Customer originalEntity = await context.Customers.FindAsync(key);
     if (originalEntity == null)
     {
         return NotFound();
     }
     else
     {
         patch.Patch(originalEntity);
         await context.SaveChangesAsync();
     }
     return Updated(originalEntity);
 }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:23,代码来源:CustomersController.cs

示例15: Patch

        public Product Patch(long id, Delta<Product> patch, HttpRequestMessage request)
        {
            var dbProduct = _db.Products.Find(id);
            if (dbProduct == null)
            {
                throw new HttpResponseException(request.CreateResponse(HttpStatusCode.NotFound));
            }

            var product = Mapper.Map<Product>(dbProduct);
            patch.Patch(product);
            if (product.ID != id)
            {
                throw new HttpResponseException(request.CreateErrorResponse(
                    HttpStatusCode.BadRequest,
                    "Changing key property is not allowed for PATCH method."));
            }

            dbProduct = Mapper.Map(product, dbProduct);
            _db.Entry(dbProduct).State = EntityState.Modified;
            _db.SaveChanges();

            return product;
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:23,代码来源:ProductRepository.cs


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