예제 #1
0
        public void RenewMembership(MembershipRenewal renewal)
        {
            this._tracer.Trace("Method: MembershipService.RenewMembership: MembershipNumber={0}", renewal.MembershipNumber);

            try
            {
                if (!string.IsNullOrEmpty(renewal.MembershipNumber))
                {
                    var sdk = ConnectionController.ConnectToCrm(this._tracer);
                    if (sdk != null)
                    {
                        _tracer.Trace("membershipTypeId={0}, amount={1}", renewal.MembershipType.MembershipTypeId, renewal.MembershipType.Price);

                        MembershipController mc = new MembershipController(sdk, this._tracer);

                        bool renewed = mc.RenewMembership(renewal);
                        this._tracer.Trace("mc.RenewMembership={0}", renewed);

                        if (!renewed)
                        {
                            throw new Exception("Unable to renew the membership, this might be because the membership is in an invalid state.");
                        }
                    }
                    else
                    {
                        string message = "Unable to connect to CRM. Check web.config";
                        this._tracer.Trace(message);
                        throw new Exception(message);
                    }
                }
                else
                {
                    throw new Exception("Invalid input. The Member cannot be null for a Membership");
                }
            }
            catch (FaultException <OrganizationServiceFault> fe)
            {
                if (fe.Detail != null)
                {
                    this._tracer.Trace(fe.Detail.ToString());
                }

                this._tracer.Trace(fe.ToString());

                string reference = renewal.MembershipNumber;
                throw new WebFaultException <Error>(ConvertToError(fe, reference), HttpStatusCode.InternalServerError);
            }
            catch (Exception ex)
            {
                this._tracer.Trace(ex.ToString());

                string reference = renewal.MembershipNumber;
                throw new WebFaultException <Error>(ConvertToError(ex, reference), HttpStatusCode.InternalServerError);
            }
            finally
            {
                // write to the log file
                this._tracer.WriteToLog(this._logPath);
            }
        }
예제 #2
0
        /// <summary>
        /// Gets a single Membership based on a Membership ID
        /// </summary>
        public Membership Get(string membershipId)
        {
            Guid id = Guid.Parse(membershipId); // fine if this crashes as the error handling will kick in.

            this._tracer.Trace("Method: MembershipService.Get");
            this._tracer.Trace("Parameters: membershipId={0}", membershipId);
            Membership membership = null;

            try
            {
                if (id != Guid.Empty)
                {
                    var sdk = ConnectionController.ConnectToCrm(this._tracer);
                    if (sdk != null)
                    {
                        MembershipController mc = new MembershipController(sdk, this._tracer);
                        membership = mc.GetMembership(id);

                        this._tracer.Trace("membership is null={0}", membership == null);

                        // if there is no membership found, throw an error back to the caller
                        if (membership == null)
                        {
                            this._tracer.Trace("membership not valid");
                            throw new Exception("Membership is not valid for renewal");
                        }
                    }
                    else
                    {
                        string message = "Unable to connect to CRM. Check web.config";
                        this._tracer.Trace(message);
                        throw new Exception(message);
                    }
                }
            }
            catch (FaultException <OrganizationServiceFault> fe)
            {
                if (fe.Detail != null)
                {
                    this._tracer.Trace(fe.Detail.ToString());
                }

                this._tracer.Trace(fe.ToString());
                throw new WebFaultException <Error>(ConvertToError(fe, DateTime.Now.Ticks.ToString()), HttpStatusCode.InternalServerError);
            }
            catch (Exception ex)
            {
                this._tracer.Trace(ex.ToString());
                throw new WebFaultException <Error>(ConvertToError(ex, DateTime.Now.Ticks.ToString()), HttpStatusCode.InternalServerError);
            }
            finally
            {
                // write to the log file
                this._tracer.WriteToLog(this._logPath);
            }

            return(membership);
        }
        public void PostDonation(Donation donation)
        {
            this._tracer.Trace("Method: Service.PostDonation");

            try
            {
                this.LogDonationInfo(donation);

                if (this.IsValidInput(donation))
                {
                    var sdk = ConnectionController.ConnectToCrm(this._tracer);
                    if (sdk != null)
                    {
                        DonationController dc = new DonationController(sdk, this._tracer);
                        dc.ProcessDonation(donation);
                        this._tracer.Trace("Donation processed");
                    }
                    else
                    {
                        string message = "Unable to connect to CRM. Check web.config";
                        this._tracer.Trace(message);
                        throw new Exception(message);
                    }
                }
                else
                {
                    throw new Exception("Invalid input. The Donor and Pledge cannot be null for a Donation");
                }
            }
            catch (FaultException <OrganizationServiceFault> fe)
            {
                if (fe.Detail != null)
                {
                    this._tracer.Trace(fe.Detail.ToString());
                }

                this._tracer.Trace(fe.ToString());

                string reference = donation != null ? donation.DpsTransactionReference : "Donation is Null";
                throw new WebFaultException <Error>(ConvertToError(fe, reference), HttpStatusCode.InternalServerError);
            }
            catch (Exception ex)
            {
                this._tracer.Trace(ex.ToString());

                string reference = donation != null ? donation.DpsTransactionReference : "Donation is Null";
                throw new WebFaultException <Error>(ConvertToError(ex, reference), HttpStatusCode.InternalServerError);
            }
            finally
            {
                // write to the log file
                this._tracer.WriteToLog(this._logPath);
            }
        }
예제 #4
0
        /// <summary>
        /// Updates the details of an existing Membership
        /// </summary>
        public void Update(Membership membership)
        {
            this._tracer.Trace("Method: MembershipService.Update");

            try
            {
                this.LogMembershipInfo(membership);

                if (this.IsValidInput(membership))
                {
                    var sdk = ConnectionController.ConnectToCrm(this._tracer);
                    if (sdk != null)
                    {
                        MembershipController mc = new MembershipController(sdk, this._tracer);
                        mc.ProcessUpdate(membership);
                        this._tracer.Trace("Membership processed");
                    }
                    else
                    {
                        string message = "Unable to connect to CRM. Check web.config";
                        this._tracer.Trace(message);
                        throw new Exception(message);
                    }
                }
                else
                {
                    throw new Exception("Invalid input. The Member cannot be null for a Membership");
                }
            }
            catch (FaultException <OrganizationServiceFault> fe)
            {
                if (fe.Detail != null)
                {
                    this._tracer.Trace(fe.Detail.ToString());
                }

                this._tracer.Trace(fe.ToString());

                string reference = membership != null ? membership.DpsTransactionReference : "Membership is Null";
                throw new WebFaultException <Error>(ConvertToError(fe, reference), HttpStatusCode.InternalServerError);
            }
            catch (Exception ex)
            {
                this._tracer.Trace(ex.ToString());

                string reference = membership != null ? membership.DpsTransactionReference : "Membership is Null";
                throw new WebFaultException <Error>(ConvertToError(ex, reference), HttpStatusCode.InternalServerError);
            }
            finally
            {
                // write to the log file
                this._tracer.WriteToLog(this._logPath);
            }
        }
        public PageData GetPageData(string regionCode)
        {
            this._tracer.Trace("Method: Service.GetPageData");
            this._tracer.Trace("Parameters: regionCode={0}", regionCode);
            PageData data = null;

            try
            {
                var sdk = ConnectionController.ConnectToCrm(this._tracer);
                if (sdk != null)
                {
                    PageController page = new PageController(sdk, this._tracer);
                    data = page.GetDonationPageData(regionCode);
                }
                else
                {
                    string message = "Unable to connect to CRM. Check web.config";
                    this._tracer.Trace(message);
                    throw new Exception(message);
                }
            }
            catch (FaultException <OrganizationServiceFault> fe)
            {
                if (fe.Detail != null)
                {
                    this._tracer.Trace(fe.Detail.ToString());
                }

                this._tracer.Trace(fe.ToString());
                throw new WebFaultException <Error>(ConvertToError(fe, DateTime.Now.Ticks.ToString()), HttpStatusCode.InternalServerError);
            }
            catch (Exception ex)
            {
                this._tracer.Trace(ex.ToString());
                throw new WebFaultException <Error>(ConvertToError(ex, DateTime.Now.Ticks.ToString()), HttpStatusCode.InternalServerError);
            }
            finally
            {
                // write to the log file
                this._tracer.WriteToLog(this._logPath);
            }

            return(data);
        }