public virtual SalesOrder_CreateOutput Create(SalesOrder_CreateInput _data)
 {
     SalesOrder_CreateOutput res = new SalesOrder_CreateOutput();
     using (AdventureWorksEntities ctx = new AdventureWorksEntities())
     {
         EntityState state = EntityState.Added;
         SalesOrder obj = new SalesOrder();
         var entry = ctx.Entry(obj);
         entry.State = state;
         entry.CurrentValues.SetValues(_data);
         // CUSTOM_CODE_START: use the Customer input parameter of Create operation below
         UpdateCustomer(ctx, obj, _data.Customer); // CUSTOM_CODE_END
         // CUSTOM_CODE_START: use the Payment input parameter of Create operation below
         UpdatePayment(ctx, obj, _data.Payment); // CUSTOM_CODE_END
         // CUSTOM_CODE_START: use the Sales input parameter of Create operation below
         UpdateSales(ctx, obj, _data.Sales); // CUSTOM_CODE_END
         // CUSTOM_CODE_START: add custom code for Create operation below
         obj.OrderDate = DateTime.Now;
         obj.ModifiedDate = DateTime.Now;
         // CUSTOM_CODE_END
         ErrorList.Current.AbortIfHasErrors(HttpStatusCode.BadRequest);
         ctx.SaveChanges();
         ServiceUtil.CopyProperties(obj, res);
     }
     return res;
 }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public virtual async Task <Output <SalesOrder_CreateOutput> > CreateAsync(SalesOrder_CreateInput _data)
        {
            HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Post, $"sales-order")
            {
                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_CreateOutput> >(content, SerializerOptions));
            }
        }
        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();
            }
        }