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();
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public virtual async Task <Output> Detail_UpdateAsync(int _salesOrderDetailId, SalesOrderDetail_UpdateInput_Data _data)
        {
            HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Put, $"sales-order/detail/{ _salesOrderDetailId }")
            {
                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>(content, SerializerOptions));
            }
        }
 public virtual void Detail_Update(int _salesOrderDetailId, SalesOrderDetail_UpdateInput_Data _data)
 {
     using (AdventureWorksEntities ctx = new AdventureWorksEntities())
     {
         SalesOrderDetail obj = ctx.SalesOrderDetail.Find(_salesOrderDetailId);
         if (obj == null)
         {
             ErrorList.Current.CriticalError(HttpStatusCode.NotFound, "SalesOrderDetail with id {0} not found", _salesOrderDetailId);
         }
         var entry = ctx.Entry(obj);
         entry.CurrentValues.SetValues(_data);
         // CUSTOM_CODE_START: use the SpecialOfferId input parameter of Detail_Update operation below
         // TODO: ??? = _data.SpecialOfferId; // CUSTOM_CODE_END
         // CUSTOM_CODE_START: use the ProductId input parameter of Detail_Update operation below
         // TODO: ??? = _data.ProductId; // CUSTOM_CODE_END
         // CUSTOM_CODE_START: add custom code for Detail_Update operation below
         // CUSTOM_CODE_END
         ErrorList.Current.AbortIfHasErrors(HttpStatusCode.BadRequest);
         ctx.SaveChanges();
     }
 }