コード例 #1
0
        public XElement GetContractByBin(string binCode)
        {
            try
            {
                crmService = new XrmServices();
                Entity contract = Contrat.GetContractNumberByBin(int.Parse(binCode), crmService);
                if (contract != null && contract.Id != Guid.Empty)
                {
                    string contractNumber = contract.GetAttributeValue <string>("new_contractnumber");

                    result.AddResultElement("contractcode", contractNumber);
                    returnCode = (int)CustomReturnCode.Success;
                }
                else
                {
                    returnCode = (int)CustomReturnCode.ContractNotFound;
                }
                result.SetError(returnCode, customError.getErrorMessage(returnCode));
            }
            catch (Exception e)
            {
                result.SetError((int)CustomReturnCode.Unknown, e.Message, e);
            }
            Dispose();
            return(result.getXml((Method == "post") ? new List <string> {
                binCode
            } : null));
        }
コード例 #2
0
        public XElement UpdateCustomerBin(string pcidssId, string binCode)
        {
            bool isUpdated = false;

            try
            {
                crmService = new XrmServices();
                int codeBin;
                if (!string.IsNullOrEmpty(pcidssId) && !string.IsNullOrEmpty(binCode) && int.TryParse(binCode.Replace(" ", ""), out codeBin))
                {
                    Entity contractId = Contrat.GetContractNumberByBin(codeBin, crmService);
                    if (contractId != null && contractId.Id != Guid.Empty)
                    {
                        Entity updateContact = Contact.GetContactById(pcidssId, crmService);
                        if (updateContact != null && updateContact.Id != Guid.Empty)
                        {
                            updateContact.Attributes.Add("new_bin", codeBin);
                            updateContact.Attributes.Add("new_contractid", contractId.ToEntityReference());
                            crmService.Update(updateContact);
                            isUpdated = true;
                            result.SetError((int)CustomReturnCode.Success, customError.getErrorMessage((int)CustomReturnCode.Success));
                        }
                        else
                        {
                            result.SetError((int)CustomReturnCode.CustomerNotFound, customError.getErrorMessage((int)CustomReturnCode.CustomerNotFound));
                        }
                    }
                    else
                    {
                        result.SetError((int)CustomReturnCode.ContractNotFound, customError.getErrorMessage((int)CustomReturnCode.ContractNotFound));
                    }
                }
                else
                {
                    throw new Exception("Paramétre incorrect");
                }
            }
            catch (Exception e)
            {
                result.SetError((int)CustomReturnCode.Unknown, e.Message, e);
            }
            Dispose();
            result.AddResultElement("resultcode", isUpdated);
            return(result.getXml((Method == "post") ? new List <string> {
                pcidssId, binCode
            } : null));
        }