本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例10: Patch
public TestItemType Patch([FromODataUri] int key, Delta<TestItemType> patch)
{
TestItemType testitemtype = db.TestItemTypes.Find(key);
patch.Patch(testitemtype);
db.SaveChanges();
return testitemtype;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}