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); }
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); }
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); }
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); }
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); }
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()); }
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); }
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); }
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; }
public TestItemType Patch([FromODataUri] int key, Delta<TestItemType> patch) { TestItemType testitemtype = db.TestItemTypes.Find(key); patch.Patch(testitemtype); db.SaveChanges(); return testitemtype; }
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); }
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); }
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); }
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); }
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; }
public async Task<IHttpActionResult> Patch([FromODataUri] string key, Delta<Customer> patch) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Customer customer = await _customerService.FindAsync(key); if (customer == null) { return NotFound(); } patch.Patch(customer); customer.ObjectState = ObjectState.Modified; try { await _unitOfWorkAsync.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(key)) { return NotFound(); } throw; } return Updated(customer); }
public async Task<IHttpActionResult> Patch([FromODataUri] Guid key, Delta<Company> patch) { Company company = await db.Companies.FindAsync(key); if (company == null) { return NotFound(); } patch.GetEntity().CompanyId = key; patch.Patch(company); Validate(company); if (!ModelState.IsValid) { return BadRequest(ModelState); } try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompanyExists(key)) { return NotFound(); } else { throw; } } return Updated(company); }
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<Basic_Information> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return BadRequest(ModelState); } Basic_Information basic_Information = await db.Basic_Information.FindAsync(key); if (basic_Information == null) { return NotFound(); } patch.Patch(basic_Information); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Basic_InformationExists(key)) { return NotFound(); } else { throw; } } return Updated(basic_Information); }
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<Product> patch) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } Product product = await this.db.Products.FindAsync(key); if (product == null) { return this.NotFound(); } patch.Patch(product); try { await this.db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!this.ProductExists(key)) { return this.NotFound(); } else { throw; } } return this.Updated(product); }
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<OrganizationIdentityDirectory> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return BadRequest(ModelState); } OrganizationIdentityDirectory organizationIdentityDirectory = await db.OrganizationIdentityDirectory.FindAsync(key); if (organizationIdentityDirectory == null) { return NotFound(); } patch.Patch(organizationIdentityDirectory); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrganizationIdentityDirectoryExists(key)) { return NotFound(); } else { throw; } } return Updated(organizationIdentityDirectory); }
public virtual async Task<IHttpActionResult> Patch([FromODataUri] int elementFieldId, Delta<UserElementField> patch) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var userElementField = await MainUnitOfWork.AllLive.SingleOrDefaultAsync(item => item.ElementFieldId == elementFieldId); if (userElementField == null) { return NotFound(); } var patchEntity = patch.GetEntity(); // TODO How is passed ModelState.IsValid? if (patchEntity.RowVersion == null) throw new InvalidOperationException("RowVersion property of the entity cannot be null"); if (!userElementField.RowVersion.SequenceEqual(patchEntity.RowVersion)) { return Conflict(); } patch.Patch(userElementField); await MainUnitOfWork.UpdateAsync(userElementField); return Ok(userElementField); }
public IHttpActionResult Patch([FromODataUri] int key, Delta<Category> patch) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Category category = db.Categories.Find(key); if (category == null) { return NotFound(); } patch.Patch(category); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(key)) { return NotFound(); } else { throw; } } return Updated(category); }
public async Task<IHttpActionResult> Patch([FromODataUri] Guid key, Delta<RepairReason> patch) { RepairReason repairReason = await db.RepairReasons.FindAsync(key); if (repairReason == null) { return NotFound(); } patch.GetEntity().RepairReasonId = key; patch.Patch(repairReason); Validate(repairReason); if (!ModelState.IsValid) { return BadRequest(ModelState); } try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RepairReasonExists(key)) { return NotFound(); } else { throw; } } return Updated(repairReason); }
public async Task<IHttpActionResult> Patch([FromODataUri]Guid jobId, [FromODataUri]Guid repairReasonId, Delta<JobRepairReason> patch) { JobRepairReason jobRepairReason = await db.JobRepairReason.FindAsync(new object[] { jobId, repairReasonId }); if (jobRepairReason == null) { return NotFound(); } patch.GetEntity().JobId = jobId; patch.GetEntity().RepairReasonId = repairReasonId; patch.Patch(jobRepairReason); Validate(patch.GetEntity()); if (!ModelState.IsValid) { return BadRequest(ModelState); } try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!JobRepairReasonExists(jobId, repairReasonId)) { return NotFound(); } else { throw; } } return Updated(jobRepairReason); }
public async Task<IHttpActionResult> Patch([FromODataUri] Guid key, Delta<WorkDone> patch) { WorkDone workDone = await db.WorkDone.FindAsync(key); if (workDone == null) { return NotFound(); } patch.GetEntity().WorkDoneId = key; patch.Patch(workDone); Validate(workDone); if (!ModelState.IsValid) { return BadRequest(ModelState); } try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WorkDoneExists(key)) { return NotFound(); } else { throw; } } return Updated(workDone); }
public IHttpActionResult Patch([FromODataUri] int key, Delta<Thread> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return BadRequest(ModelState); } Thread thread = db.Threads.Find(key); if (thread == null) { return NotFound(); } patch.Patch(thread); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ThreadExists(key)) { return NotFound(); } else { throw; } } return Updated(thread); }
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<Member> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return BadRequest(ModelState); } Member member = await db.Members.FindAsync(key); if (member == null) { return NotFound(); } patch.Patch(member); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MemberExists(key)) { return NotFound(); } else { throw; } } return Updated(member); }
public IHttpActionResult Patch([FromODataUri] int key, Delta<DeltaEnumCustomer> patch) { if (!ModelState.IsValid) { return BadRequest(ModelState); } DeltaEnumCustomer customer = GetCustomers().FirstOrDefault(e => e.Id == key); if (customer == null) { return NotFound(); } patch.Patch(customer); return Updated(customer); }
public IHttpActionResult Patch([FromODataUri] int key, Delta<Virus> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return BadRequest(ModelState); } Virus virus = db.Viruses.Find(key); if (virus == null) { return NotFound(); } patch.Patch(virus); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!VirusExists(key)) { return NotFound(); } else { throw; } } return Updated(virus); }
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<Hazard> patch) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Hazard hazard = await db.Hazards.FindAsync(key); if (hazard == null) { return NotFound(); } patch.Patch(hazard); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HazardExists(key)) { return NotFound(); } else { throw; } } return Updated(hazard); }