如何在Typescript中编写OData批处理HttpFetch?

时间:2018-11-15 15:30:11

标签: typescript http odata http-patch

“我的当前”(播放)方法无法按预期工作。我真正需要做的是将其更改为对组进行单个请求。我完全不知所措,怎么办,除了可能的话。

这就是我所拥有的:

  editBulkPlan(plans: Update<Plan>[]): Observable<Plan>[] {
    this.log("Editing a buncha plans  Plan");

    let list: Observable<Plan>[] = new Array();


    plans.forEach(x => {
      list.push(this.editPlan(this.http.patch<Plan>(this.odataUrl + "Plans(" + x.id + ")", x.changes, this.httpPatchOptions)));
    });


    return list;

    //return this.http.patch<Plan[]>(this.odataUrl + "Plans(" + plan.id + ")", plans.changes, this.httpPatchOptions);
  }

和控制器:

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

        using (CreateTimedTelemetryTrace())
        {
            var entity = await DataContext.Plans.FindAsync(key);
            if (entity == null)
            {
                return NotFound();
            }

            plan.Patch(entity);

            var now = DateTime.UtcNow;
            entity.UpdatedBy = RequestContext.Principal.Identity.Name;
            entity.UpdatedAt = now;

            if (entity.TestType_Id == 0)
            {
                entity.TestType_Id = 1; // Override null/0 with N/A
            }

            try
            {
                await DataContext.SaveChangesAsync();
            }
            catch (DbUpdateException exc)
            {
                if (!PlanExists(key))
                {
                    return NotFound();
                }
                TelemetryClient.TrackException(exc);
                throw;
            }

            return Updated(entity);
        }
    }

我需要的是一个请求,以及相应的更改。

0 个答案:

没有答案