public async Task <ActionResult> CreateAsync([FromBody] SalesOrder_CreateInput _data) { ActionResult response; try { if (ModelState.IsValid) { Output <SalesOrder_CreateOutput> output = await svc.CreateAsync(_data); response = StatusCode((int)output.HttpStatus, output); return(response); } else { currentErrors.AddModelErrors(ModelState); } } catch (Exception ex) { currentErrors.MergeWith(errorsParser.FromException(ex)); } response = StatusCode((int)currentErrors.HttpStatus, new Output(currentErrors)); return(response); }
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)); }
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); }
protected virtual Output <SalesOrder_CreateOutput> SalesOrder_Create(object options) { SalesOrder_CreateInput _data = ToDataContract <SalesOrder_CreateInput>(options); using (var s = ServiceProvider.CreateScope()) { var output = s.ServiceProvider.GetService <ISalesOrderService>().Create(_data); FromDataContract(output?.Result, options); return(output); } }
protected virtual async Task <Output <SalesOrder_CreateOutput> > SalesOrder_CreateAsync(object options) { SalesOrder_CreateInput _data = ToDataContract <SalesOrder_CreateInput>(options); using (var s = ServiceProvider.CreateScope()) { var output = await s.ServiceProvider.GetService <ISalesOrderService>().CreateAsync(_data); await FromDataContractAsync(output?.Result, options); return(output); } }
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(); } } }
public ActionResult Create([FromBody] SalesOrder_CreateInput _data) { ActionResult response = null; try { if (ModelState.IsValid) { Output <SalesOrder_CreateOutput> output = svc.Create(_data); response = StatusCode((int)output.HttpStatus, output); return(response); } else { ModelValidation.AddModelErrors(currentErrors, ModelState); } } catch (Exception ex) { currentErrors.MergeWith(errorsParser.FromException(ex)); } response = StatusCode((int)currentErrors.HttpStatus, new Output(currentErrors)); return(response); }