public override void OnRunCreateCustomsDeclaration(WorkItem context, object caller, object target)
        {
            if (context.Items.Contains("IgnoreClose"))
            {
                context.Items.Remove(context.Items["IgnoreClose"]);
            }

            if (context.Items.Contains("DialogResult"))
            {
                context.Items.Remove(context.Items["DialogResult"]);
            }

            RunCreateCustomsDeclarationActionParameters actionParameters = target as RunCreateCustomsDeclarationActionParameters;



            CreateCustomsDeclarationRequest serviceRequest = new CreateCustomsDeclarationRequest();

            serviceRequest.CreateCustomsDeclarationParameters = new CreateCustomsDeclarationParameters();

            serviceRequest.CreateCustomsDeclarationParameters.CustomsDeclarationType = actionParameters.CustomsDeclarationType;
            serviceRequest.CreateCustomsDeclarationParameters.CustomsClearanceType   = actionParameters.CustomsClearanceType;
            serviceRequest.CreateCustomsDeclarationParameters.CustomsDeclarantId     = actionParameters.CustomsDeclarantId;
            serviceRequest.CreateCustomsDeclarationParameters.UserId                = actionParameters.UserId;
            serviceRequest.CreateCustomsDeclarationParameters.ClientId              = actionParameters.ClientId;
            serviceRequest.CreateCustomsDeclarationParameters.WarehouseId           = actionParameters.WarehouseId;
            serviceRequest.CreateCustomsDeclarationParameters.PayCustomsDeclaration = actionParameters.PayCustomsDeclaration;
            serviceRequest.CreateCustomsDeclarationParameters.CustomsDeclaration    = actionParameters.CustomsDeclaration;
            try
            {
                CreateCustomsDeclarationResponse serviceResponse = CustomsDeclarationService.CreateCustomsDeclaration(serviceRequest);

                context.Items.Add(serviceResponse, "CreateCustomsDeclarationResponse");

                context.Items.Add(DialogResult.Ok, "DialogResult");

                // postback in parent workitem
                Bookmark bookmark = new Bookmark()
                {
                    RowIdentity = serviceResponse.CreateCustomsDeclarationResult.RowIdentities.FirstOrDefault(), MultipleSelection = serviceResponse.CreateCustomsDeclarationResult.RowIdentities.Select(i => new Bookmark()
                    {
                        RowIdentity = i
                    }).ToList()
                };
                context.Parent.Items.Add(bookmark);
            }
            catch (FaultException <ValidationFault> ex)
            {
                if (ex.Detail.ValidationError == ValidationError.NullValue)
                {
                    throw new Imi.SupplyChain.UX.NullValidationException(ex.Detail.Message, ex.Detail.ParameterName);
                }
                else
                {
                    throw new Imi.SupplyChain.UX.ValidationException(ex.Detail.Message, ex.Detail.ParameterName);
                }
            }
        }
Ejemplo n.º 2
0
        public override void OnCreateCustomsDeclarationRunCreateCustomsDeclaration(WorkItem context, object caller, object target)
        {
            WorkItem wi = GetModuleWorkItem(context);

            if (wi.Items.FindByType <RunCreateCustomsDeclarationAction>().Count == 0)
            {
                wi.Items.AddNew <RunCreateCustomsDeclarationAction>();
            }

            CreateCustomsDeclarationViewResult          viewResult       = null;
            RunCreateCustomsDeclarationActionParameters actionParameters = null;
            CreateCustomsDeclarationViewToRunCreateCustomsDeclarationActionTranslator translator = null;
            bool isItemSelected = false;

            if (context.Items.FindByType <CreateCustomsDeclarationViewToRunCreateCustomsDeclarationActionTranslator>().Count > 0)
            {
                translator = context.Items.FindByType <CreateCustomsDeclarationViewToRunCreateCustomsDeclarationActionTranslator>().Last();
            }
            else
            {
                translator = context.Items.AddNew <CreateCustomsDeclarationViewToRunCreateCustomsDeclarationActionTranslator>();
            }

            if (context.Items.FindByType <CreateCustomsDeclarationViewResult>().Count > 0)
            {
                viewResult     = context.Items.FindByType <CreateCustomsDeclarationViewResult>().Last();
                isItemSelected = true;
            }
            else
            {
                viewResult = new CreateCustomsDeclarationViewResult();

                if (context.Items.FindByType <CreateCustomsDeclarationViewParameters>().Count() > 0)
                {
                    CreateCustomsDeclarationViewParameters viewParameters = context.Items.FindByType <CreateCustomsDeclarationViewParameters>().Last();

                    viewResult.CustomsDeclarantId = viewParameters.CustomsDeclarantId;
                }
            }

            actionParameters = translator.Translate(viewResult);
            actionParameters.IsItemSelected          = isItemSelected;
            actionParameters.IsMultipleItemsSelected = false;

            ICreateCustomsDeclarationView view = context.SmartParts.FindByType <CreateCustomsDeclarationView>().Last();

            try
            {
                if (!view.Validate())
                {
                    return;
                }

                ActionCatalog.Execute(ActionNames.RunCreateCustomsDeclaration, context, caller, actionParameters);

                if (isItemSelected)
                {
                    if (context.Items.Get("CreateCustomsDeclarationResponse") != null)
                    {
                        CreateCustomsDeclarationResponse serviceResponce = (CreateCustomsDeclarationResponse)context.Items.Get("CreateCustomsDeclarationResponse");

                        if (serviceResponce.CreateCustomsDeclarationResult != null)
                        {
                            if (serviceResponce.CreateCustomsDeclarationResult.CustomsDeclarationId != null)
                            {
                                viewResult.CustomsDeclarationId = serviceResponce.CreateCustomsDeclarationResult.CustomsDeclarationId;
                            }
                        }
                    }
                }

                // Check if view should be closed.
                bool ignoreClosing = ((context.Items.Get("IgnoreClose") != null) &&
                                      ((bool)(context.Items.Get("IgnoreClose"))));

                if (!ignoreClosing)
                {
                    /* close wrapper if view was dynamically loaded */
                    object wrapper = context.Items.Get("Imi.SupplyChain.Warehouse.UX.Views.CustomsDeclaration.ICreateCustomsDeclarationView");

                    if (wrapper == null)
                    {
                        WorkspaceLocatorService.FindContainingWorkspace(context, view).Close(view);
                    }
                    else
                    {
                        WorkspaceLocatorService.FindContainingWorkspace(context, wrapper).Close(wrapper);
                    }
                }
            }
            catch (Imi.SupplyChain.UX.ValidationException ex)
            {
                view.HandleValidationResult(ValidationHelper.ConvertToResult((Imi.SupplyChain.UX.ValidationException)ex));
            }
        }