public virtual Output <SalesOrder_UpdateOutput> Update(int _salesOrderId, SalesOrder_UpdateInput_Data _data) { // CUSTOM_CODE_START: add custom security checks for Update operation below // CUSTOM_CODE_END SalesOrder_UpdateOutput res = new SalesOrder_UpdateOutput(); try { SalesOrder obj = ctx.FindEntity <SalesOrder>(currentErrors, _salesOrderId); var entry = ctx.Entry(obj); entry.CurrentValues.SetValues(_data); // CUSTOM_CODE_START: use the Customer input parameter of Update operation below UpdateCustomer(obj, _data.Customer); // CUSTOM_CODE_END // CUSTOM_CODE_START: use the Payment input parameter of Update operation below UpdatePayment(obj, _data.Payment); // CUSTOM_CODE_END // CUSTOM_CODE_START: use the Sales input parameter of Update operation below UpdateSalesInfo(obj, _data.Sales); // CUSTOM_CODE_END // CUSTOM_CODE_START: add custom code for Update operation below obj.ModifiedDate = DateTime.Now; // CUSTOM_CODE_END currentErrors.AbortIfHasErrors(); ctx.SaveChanges(); ServiceUtil.CopyProperties(obj, res); } catch (Exception ex) { currentErrors.MergeWith(errorParser.FromException(ex)); } return(new Output <SalesOrder_UpdateOutput>(currentErrors, res)); }
public async Task <ActionResult> UpdateAsync([FromRoute] int _salesOrderId, [FromBody] SalesOrder_UpdateInput_Data _data) { ActionResult response; try { if (ModelState.IsValid) { Output <SalesOrder_UpdateOutput> output = await svc.UpdateAsync(_salesOrderId, _data); response = StatusCode((int)output.HttpStatus, output); return(response); } else { currentErrors.AddModelErrors(ModelState); } } catch (Exception ex) { currentErrors.MergeWith(errorsParser.FromException(ex)); } response = StatusCode((int)currentErrors.HttpStatus, new Output(currentErrors)); return(response); }
protected virtual Output <SalesOrder_UpdateOutput> SalesOrder_Update(object options) { int _salesOrderId = (int)SalesOrderIdProperty.TransportValue; SalesOrder_UpdateInput_Data _data = ToDataContract <SalesOrder_UpdateInput_Data>(options); using (var s = ServiceProvider.CreateScope()) { var output = s.ServiceProvider.GetService <ISalesOrderService>().Update(_salesOrderId, _data); FromDataContract(output?.Result, options); return(output); } }
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(); } } }
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(); } }