Exemple #1
0
        public virtual Output <SalesOrder_CreateOutput> Create(SalesOrder_CreateInput _data)
        {
            // CUSTOM_CODE_START: add custom security checks for Create operation below
            // CUSTOM_CODE_END
            SalesOrder_CreateOutput res = new SalesOrder_CreateOutput();

            try
            {
                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(obj, _data.Customer); // CUSTOM_CODE_END
                // CUSTOM_CODE_START: use the Payment input parameter of Create operation below
                UpdatePayment(obj, _data.Payment);   // CUSTOM_CODE_END
                // CUSTOM_CODE_START: use the Sales input parameter of Create operation below
                UpdateSalesInfo(obj, _data.Sales);   // CUSTOM_CODE_END
                // CUSTOM_CODE_START: add custom code for Create operation below
                obj.OrderDate    = DateTime.Now;
                obj.ModifiedDate = DateTime.Now;
                obj.Rowguid      = Guid.NewGuid();
                // CUSTOM_CODE_END
                currentErrors.AbortIfHasErrors();
                ctx.SaveChanges();
                ServiceUtil.CopyProperties(obj, res);
            }
            catch (Exception ex)
            {
                currentErrors.MergeWith(errorParser.FromException(ex));
            }
            return(new Output <SalesOrder_CreateOutput>(currentErrors, res));
        }
Exemple #2
0
        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);
        }