Example #1
0
        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();
                }
            }
        }
Example #2
0
        public ActionResult Detail_Create([FromRoute] int _salesOrderId, [FromBody] SalesOrderDetail_CreateInput_Data _data)
        {
            ActionResult response = null;

            try
            {
                if (ModelState.IsValid)
                {
                    Output <SalesOrderDetail_CreateOutput> output = svc.Detail_Create(_salesOrderId, _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);
        }