public virtual SalesOrderDetail_CreateOutput Detail_Create(SalesOrderDetail_CreateInput _data) { SalesOrderDetail_CreateOutput res = new SalesOrderDetail_CreateOutput(); using (AdventureWorksEntities ctx = new AdventureWorksEntities()) { EntityState state = EntityState.Added; SalesOrderDetail obj = new SalesOrderDetail(); var entry = ctx.Entry(obj); entry.State = state; entry.CurrentValues.SetValues(_data); obj.SalesOrderObject = ctx.SalesOrder.Find(_data.SalesOrderId); if (obj.SalesOrderObject == null) { ErrorList.Current.AddError("Invalid value {0} for parameter SalesOrderId. Cannot find the corresponding SalesOrder object.", _data.SalesOrderId); } // CUSTOM_CODE_START: use the SpecialOfferId input parameter of Detail_Create operation below // TODO: ??? = _data.SpecialOfferId; // CUSTOM_CODE_END // CUSTOM_CODE_START: use the ProductId input parameter of Detail_Create operation below // TODO: ??? = _data.ProductId; // CUSTOM_CODE_END // CUSTOM_CODE_START: add custom code for Detail_Create operation below // CUSTOM_CODE_END ErrorList.Current.AbortIfHasErrors(HttpStatusCode.BadRequest); ctx.SaveChanges(); ServiceUtil.CopyProperties(obj, res); } return(res); }
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) { SalesOrderDetail_CreateInput inDetail_Create = new SalesOrderDetail_CreateInput(); obj.ToDataContract(inDetail_Create); SalesOrderDetail_CreateOutput outDetail_Create; using (TimeTracker.ServiceCall) outDetail_Create = svcSalesOrder.Detail_Create(inDetail_Create); obj.FromDataContract(outDetail_Create); IsNew = false; } else { SalesOrderDetail_UpdateInput_Data inDetail_Update_Data = new SalesOrderDetail_UpdateInput_Data(); obj.ToDataContract(inDetail_Update_Data); using (TimeTracker.ServiceCall) svcSalesOrder.Detail_Update((int)obj.SalesOrderDetailIdProperty.TransportValue, inDetail_Update_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(); } } }