public virtual async Task <Output <SalesOrderDetail_CreateOutput> > Detail_CreateAsync(int _salesOrderId, SalesOrderDetail_CreateInput_Data _data)
        {
            SalesOrderDetail_CreateOutput res = new SalesOrderDetail_CreateOutput();

            try
            {
                currentErrors.AbortIfHasErrors();

                // CUSTOM_CODE_START: add custom security checks for Detail_Create operation below
                // CUSTOM_CODE_END
                EntityState      state = EntityState.Added;
                SalesOrderDetail obj   = new SalesOrderDetail();
                var entry = ctx.Entry(obj);
                entry.State      = state;
                obj.SalesOrderId = _salesOrderId;
                entry.CurrentValues.SetValues(_data);
                await ctx.ValidateKeyAsync <SalesOrder>(currentErrors, "SalesOrderId", _salesOrderId);

                await ctx.ValidateKeyAsync <SpecialOfferProduct>(currentErrors, "SpecialOfferId, ProductId", _data.SpecialOfferId, _data.ProductId);

                // CUSTOM_CODE_START: add custom code for Detail_Create operation below
                UpdateOrderDetail(obj);
                // CUSTOM_CODE_END
                currentErrors.AbortIfHasErrors();
                await ctx.SaveChangesAsync();

                ServiceUtil.CopyProperties(obj, res);
            }
            catch (Exception ex)
            {
                currentErrors.MergeWith(errorParser.FromException(ex));
            }
            return(await Task.FromResult(new Output <SalesOrderDetail_CreateOutput>(currentErrors, res)));
        }
예제 #2
0
        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);
        }