Exemplo n.º 1
0
        public AccountHierarchyResponse RemoveAccountFromGroup(string accountId)
        {
            AccountHierarchyResponse response = new AccountHierarchyResponse();

            var groupsAssigned = IsAccountAssignedToHierarchy(accountId);
            var childGroup     = new AccountHierarchyChildResponse();

            foreach (var child in groupsAssigned.Children)
            {
                if (child.AssignedToAccount)
                {
                    childGroup = child;
                }
            }

            var request = new BusinessPartnerHierarchyMaintainRequestMessage_sync();

            //groups
            var groups = new BusinessPartnerHierarchyMaintainRequestGroup[1];

            groups[0]      = new BusinessPartnerHierarchyMaintainRequestGroup();
            groups[0].ID   = childGroup.ChildId;
            groups[0].Name = childGroup.ChildName;
            //groups[0].ParentGroupID = groupsAssigned.ParentGroupId;
            var assignAccount = new BusinessPartnerHierarchyMaintainRequestGroupBusinessPartner();

            assignAccount.InternalID = accountId;
            var bp = new BusinessPartnerHierarchyMaintainRequestGroup();

            groups[0].BusinessPartner                        = new BusinessPartnerHierarchyMaintainRequestGroupBusinessPartner[1];
            groups[0].BusinessPartner[0]                     = new BusinessPartnerHierarchyMaintainRequestGroupBusinessPartner();
            groups[0].BusinessPartner[0]                     = assignAccount;
            groups[0].BusinessPartner[0].actionCode          = ActionCode.Item03;
            groups[0].BusinessPartner[0].actionCodeSpecified = true;

            //new hierarchy id
            BusinessPartnerHierarchyMaintainRequest hierarchy = new BusinessPartnerHierarchyMaintainRequest();

            AccountHierarchyManageService.BusinessPartnerHierarchyID parentId = new AccountHierarchyManageService.BusinessPartnerHierarchyID();
            parentId.Value = groupsAssigned.ParentId;

            //set hierarchy id, name, and groups;
            hierarchy.ID    = parentId;
            hierarchy.Name  = groupsAssigned.ParentName;
            hierarchy.Group = groups;
            request.BusinessPartnerHierarchy    = new BusinessPartnerHierarchyMaintainRequest[1];
            request.BusinessPartnerHierarchy[0] = new BusinessPartnerHierarchyMaintainRequest();
            request.BusinessPartnerHierarchy[0] = hierarchy;

            var xml = SapXmlExtractor.GetXmlString(request);

            BusinessPartnerHierarchyMaintainConfirmationMessage_sync sapResponse = _manageClient.MaintainBundle(request);

            response = SetAccountHierarchyManageResponse(sapResponse);
            //var newResponse = GetAccountHierarchyById(response.ParentId);

            return(response);
        }
Exemplo n.º 2
0
        public AccountHierarchyResponse SetAccountToGroup(AccountHierarchyRequest accountHierarchy, string accountId)
        {
            AccountHierarchyResponse response = new AccountHierarchyResponse();

            var groupsAssigned = IsAccountAssignedToHierarchy(accountId);

            if (!string.IsNullOrEmpty(groupsAssigned.ParentId))
            {
                var removeResponse = RemoveAccountFromGroup(accountId);
                if (removeResponse.Errors.Count > 0)
                {
                    return(removeResponse);
                }
            }

            var request = new BusinessPartnerHierarchyMaintainRequestMessage_sync();

            //groups
            var groups = new BusinessPartnerHierarchyMaintainRequestGroup[1];

            groups[0]               = new BusinessPartnerHierarchyMaintainRequestGroup();
            groups[0].ID            = accountHierarchy.childGroupId;
            groups[0].ParentGroupID = accountHierarchy.ParentGroupId;
            var assignAccount = new BusinessPartnerHierarchyMaintainRequestGroupBusinessPartner();

            assignAccount.InternalID = accountId;
            var bp = new BusinessPartnerHierarchyMaintainRequestGroup();

            groups[0].BusinessPartner                        = new BusinessPartnerHierarchyMaintainRequestGroupBusinessPartner[1];
            groups[0].BusinessPartner[0]                     = new BusinessPartnerHierarchyMaintainRequestGroupBusinessPartner();
            groups[0].BusinessPartner[0]                     = assignAccount;
            groups[0].BusinessPartner[0].actionCode          = ActionCode.Item01;
            groups[0].BusinessPartner[0].actionCodeSpecified = true;


            //new hierarchy id
            BusinessPartnerHierarchyMaintainRequest hierarchy = new BusinessPartnerHierarchyMaintainRequest();

            AccountHierarchyManageService.BusinessPartnerHierarchyID parentId = new AccountHierarchyManageService.BusinessPartnerHierarchyID();
            parentId.Value = accountHierarchy.ParentId;

            //set hierarchy id, name, and groups;
            hierarchy.ID    = parentId;
            hierarchy.Name  = accountHierarchy.ParentName;
            hierarchy.Group = groups;
            request.BusinessPartnerHierarchy    = new BusinessPartnerHierarchyMaintainRequest[1];
            request.BusinessPartnerHierarchy[0] = new BusinessPartnerHierarchyMaintainRequest();
            request.BusinessPartnerHierarchy[0] = hierarchy;

            string requestXml = SapXmlExtractor.GetXmlString(request);
            BusinessPartnerHierarchyMaintainConfirmationMessage_sync sapResponseCheck = new BusinessPartnerHierarchyMaintainConfirmationMessage_sync();

            try
            {
                sapResponseCheck = _manageClient.CheckMaintainBundle(request);
            }
            catch (Exception ex)
            {
            }

            if (sapResponseCheck.Log != null)
            {
                if (sapResponseCheck.Log.MaximumLogItemSeverityCode.Equals("3"))
                {
                    return(SetAccountHierarchyManageResponse(sapResponseCheck));
                }
            }

            BusinessPartnerHierarchyMaintainConfirmationMessage_sync sapResponse = _manageClient.MaintainBundle(request);

            response = SetAccountHierarchyManageResponse(sapResponse);
            var newResponse = GetAccountHierarchyById(response.ParentId, accountId);

            return(newResponse);
        }
Exemplo n.º 3
0
        public AccountHierarchyResponse SetAccountHierarchy(AccountHierarchyRequest accountHierarchy, string accountId)
        {
            AccountHierarchyResponse response = new AccountHierarchyResponse();
            var request = new BusinessPartnerHierarchyMaintainRequestMessage_sync();

            //groups
            var groups = new BusinessPartnerHierarchyMaintainRequestGroup[4];

            for (int i = 0; i < 4; i++)
            {
                groups[i] = new BusinessPartnerHierarchyMaintainRequestGroup();
            }

            //set parent
            groups[0].ID                  = GenerateHierarchyIds(accountId, 0);
            groups[0].Name                = accountHierarchy.ParentName;
            groups[0].actionCode          = ActionCode.Item01;
            groups[0].actionCodeSpecified = true;
            groups[0].businessPartnerListCompleteTransmissionIndicator          = true;
            groups[0].businessPartnerListCompleteTransmissionIndicatorSpecified = true;

            //set children
            for (int i = 1; i < groups.Length; i++)
            {
                groups[i].ID                  = GenerateHierarchyIds(accountId, i);
                groups[i].Name                = GenerateHierarchyNames(i);
                groups[i].ParentGroupID       = groups[0].ID;
                groups[i].actionCode          = ActionCode.Item01;
                groups[i].actionCodeSpecified = true;
                groups[i].businessPartnerListCompleteTransmissionIndicator          = true;
                groups[i].businessPartnerListCompleteTransmissionIndicatorSpecified = true;

                if (accountHierarchy.AssignTo == i)
                {
                    var assignAccount = new BusinessPartnerHierarchyMaintainRequestGroupBusinessPartner();
                    assignAccount.InternalID = accountId;
                    var bp = new BusinessPartnerHierarchyMaintainRequestGroup();
                    groups[i].BusinessPartner                        = new BusinessPartnerHierarchyMaintainRequestGroupBusinessPartner[1];
                    groups[i].BusinessPartner[0]                     = new BusinessPartnerHierarchyMaintainRequestGroupBusinessPartner();
                    groups[i].BusinessPartner[0]                     = assignAccount;
                    groups[i].BusinessPartner[0].actionCode          = ActionCode.Item01;
                    groups[i].BusinessPartner[0].actionCodeSpecified = true;
                }
            }

            //create new hierarchy
            BusinessPartnerHierarchyMaintainRequest hierarchy = new BusinessPartnerHierarchyMaintainRequest();

            AccountHierarchyManageService.BusinessPartnerHierarchyID parentId = new AccountHierarchyManageService.BusinessPartnerHierarchyID();
            parentId.Value = "";

            //set hierarchy id, name, and groups;
            hierarchy.ID                  = parentId;
            hierarchy.Name                = accountHierarchy.ParentName;
            hierarchy.actionCode          = ActionCode.Item01;
            hierarchy.actionCodeSpecified = true;
            hierarchy.Group               = groups;
            hierarchy.groupListCompleteTransmissionIndicator          = true;
            hierarchy.groupListCompleteTransmissionIndicatorSpecified = true;

            request.BusinessPartnerHierarchy    = new BusinessPartnerHierarchyMaintainRequest[1];
            request.BusinessPartnerHierarchy[0] = new BusinessPartnerHierarchyMaintainRequest();
            request.BusinessPartnerHierarchy[0] = hierarchy;

            BusinessPartnerHierarchyMaintainConfirmationMessage_sync sapResponse = _manageClient.MaintainBundle(request);

            response = SetAccountHierarchyManageResponse(sapResponse);

            if (response.Errors.Count > 0)
            {
                return(response);
            }

            var newResponse = GetAccountHierarchyById(response.ParentId, accountId);

            return(newResponse);
        }