protected virtual void btnSave_Click(object sender, EventArgs e) { obj.Validate(true); ErrorList valErr = obj.GetValidationErrors(); errors.List.DataSource = valErr.Errors; errors.List.DataBind(); if (valErr.HasErrors()) return; ISalesOrderService svcSalesOrder = DI.Resolve<ISalesOrderService>(); try { // for new objects create the object and store its key if (IsNew) { SalesOrder_CreateInput inCreate = new SalesOrder_CreateInput(); obj.ToDataContract(inCreate); SalesOrder_CreateOutput outCreate; using (TimeTracker.ServiceCall) outCreate = svcSalesOrder.Create(inCreate); obj.FromDataContract(outCreate); IsNew = false; } else { SalesOrder_UpdateInput_Data inUpdate_Data = new SalesOrder_UpdateInput_Data(); obj.ToDataContract(inUpdate_Data); using (TimeTracker.ServiceCall) svcSalesOrder.Update((int)obj.SalesOrderIdProperty.TransportValue, inUpdate_Data); } obj.SetModified(false, true); OnSaved(EventArgs.Empty); } catch(Exception ex) { errors.List.DataSource = ErrorList.FromException(ex).Errors; errors.List.DataBind(); } finally { if (svcSalesOrder is IDisposable) ((IDisposable)svcSalesOrder).Dispose(); } }
/// <inheritdoc/> public virtual async Task <Output <SalesOrder_UpdateOutput> > UpdateAsync(int _salesOrderId, SalesOrder_UpdateInput_Data _data) { HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Put, $"sales-order/{ _salesOrderId }") { Content = new StringContent(JsonSerializer.Serialize(_data), Encoding.UTF8, "application/json") }; using (var resp = await Http.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead)) { var content = await resp.Content.ReadAsStreamAsync(); return(await JsonSerializer.DeserializeAsync <Output <SalesOrder_UpdateOutput> >(content, SerializerOptions)); } }
public virtual void Update(int _salesOrderId, SalesOrder_UpdateInput_Data _data) { using (AdventureWorksEntities ctx = new AdventureWorksEntities()) { SalesOrder obj = ctx.SalesOrder.Find(_salesOrderId); if (obj == null) { ErrorList.Current.CriticalError(HttpStatusCode.NotFound, "SalesOrder with id {0} not found", _salesOrderId); } var entry = ctx.Entry(obj); entry.CurrentValues.SetValues(_data); // CUSTOM_CODE_START: use the Customer input parameter of Update operation below UpdateCustomer(ctx, obj, _data.Customer); // CUSTOM_CODE_END // CUSTOM_CODE_START: use the Payment input parameter of Update operation below UpdatePayment(ctx, obj, _data.Payment); // CUSTOM_CODE_END // CUSTOM_CODE_START: use the Sales input parameter of Update operation below UpdateSales(ctx, obj, _data.Sales); // CUSTOM_CODE_END // CUSTOM_CODE_START: add custom code for Update operation below obj.ModifiedDate = DateTime.Now; // CUSTOM_CODE_END ErrorList.Current.AbortIfHasErrors(HttpStatusCode.BadRequest); ctx.SaveChanges(); } }