Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        /// TODO: doesn't confirm to DRY princple - must be a better way to do this
        public static new MembershipOperationStatus CreateFromException(string message, Exception ex)
        {
            MembershipOperationStatus opStatus = new MembershipOperationStatus
            {
                Status = false,
                Message = message,
                OperationId = null
            };

            if (ex != null)
            {
                opStatus.ExceptionMessage = ex.Message;
                opStatus.ExceptionStackTrace = ex.StackTrace;
                opStatus.ExceptionInnerMessage = (ex.InnerException == null) ? null : ex.InnerException.Message;
                opStatus.ExceptionInnerStackTrace = (ex.InnerException == null) ? null : ex.InnerException.StackTrace;
            }
            return opStatus;
        }
Exemplo n.º 2
0
        public MembershipOperationStatus CreateMembership(Membership membership)
        {
            var opStatus = new MembershipOperationStatus { Status = true };

            //if there is not an existing CARE contact for this membership, create one..
            //if (membership.ExternalContactNumber == 0)
            //{
            //    opStatus = CreateContact(contact);
            //    if (!opStatus.Status)
            //    {
            //        return opStatus;
            //    }
            //    else
            //    {
            //        contact.ExternalContactNumber = opStatus.UpdatedContact.ExternalContactNumber;
            //        contact.ExternalAddressNumber = opStatus.UpdatedContact.ExternalAddressNumber;
            //    }
            //}

            //set up the web service
            var careWebServices = new CARECustomerPortalExtensions.CareWebServices.NDataAccessSoapClient();
            string sendXML = String.Format("<Parameters>" +
                "<PayerContactNumber>{0}</PayerContactNumber>" +
                "<PayerAddressNumber>{1}</PayerAddressNumber>" +
                "<StartDate>{2}</StartDate>" +
                "<PaymentFrequency>{3}</PaymentFrequency>" +
                "<Source>FSC</Source>" +
                "<ReasonForDespatch>{5}</ReasonForDespatch>" +
                "<PaymentMethod>{4}</PaymentMethod>" +
                "<MembershipType>{5}</MembershipType>" +
                "<Joined>{2}</Joined>" +
                "<BankAccount>B1</BankAccount>" +
                "<SortCode>{6}</SortCode>" +
                "<AccountNumber>{7}</AccountNumber>" +
                "<AccountName>{8}</AccountName>" +
                "<Branch>B1</Branch>" +
                "<UserLogname>fscweb</UserLogname>" +
                "</Parameters>",
                membership.ExternalContactNumber, membership.ExternalAddressNumber, DateTime.Now.ToShortDateString(), membership.MembershipPaymentFrequency, membership.MembershipPaymentMethod, membership.MembershipType, membership.SortCode, membership.BankAccountNumber, membership.BankAccountName
                );

            //Load xmldata into XDocument Object
            XDocument sendingXMLDoc = XDocument.Parse(sendXML);

            string returnXML = careWebServices.AddMembership(sendingXMLDoc.ToString());

            XDocument receivingXMLDoc = XDocument.Parse(returnXML);
            XElement resultElement = receivingXMLDoc.Element("Result");
            if (resultElement.Element("ErrorMessage") != null)
            {
                string errorMessage = resultElement.Element("ErrorMessage").Value;
                opStatus = MembershipOperationStatus.CreateFromException("Error creating membership in CARE: " + errorMessage, new CareException());
                opStatus.Status = false;
            }
            else
            {
                try
                {
                    int careMemberNumber = Convert.ToInt32(receivingXMLDoc.Element("Result")
                        .Element("MemberNumber").Value);
                    string careMessage = receivingXMLDoc.Element("Result")
                        .Element("InformationMessage").Value.ToString();
                    membership.ExternalMemberNumber = careMemberNumber;
                    opStatus.Message = "Your membership has been created successfully";
                    opStatus.UpdatedMembership = membership;

                }
                catch (Exception e)
                {
                    opStatus = MembershipOperationStatus.CreateFromException("Error creating membership in CARE: " + e.Message, e);
                    opStatus.Status = false;
                }
            }
            return opStatus;
        }