示例#1
0
        public static CustomerSite UpdateCustomerSite(CustomerSite request)
        {
            // There is no way to update the customer site with the web service - it only allows you to set all the fields.
            // Essentially, it's an all-or-none approach.
            // This method will let us update only the fields we want to update.

            // If the customer site passed is null, or we don't have the CustomerID set, stop here.
            if (request == null || request.CustomerID == 0)
            {
                return(request);
            }


            // First, get the existing customer's site info
            var customerSite = GetCustomerSite(request.CustomerID);

            if (customerSite != null)
            {
                // Determine if the web alias has changed between the request and the existing data.
                // If it isn't available, set the requested web alias to null so we don't attempt to update it.
                if (request.WebAlias.IsNullOrEmpty())
                {
                    request.WebAlias = customerSite.WebAlias;
                }
                else if (request.WebAlias.ToUpper() != customerSite.WebAlias.ToUpper() && !IsWebAliasAvailable(request.CustomerID, request.WebAlias))
                {
                    request.WebAlias = null;
                }

                // Reflect each property and populate it if the requested value is not null.
                // This does nto currently take INTs into account:
                // The properties in the CustomerSiteResponse object in the Exigo API are all strings as of this writing on 7/8/2014.
                var customerSiteType = customerSite.GetType();
                foreach (var property in customerSiteType.GetProperties())
                {
                    if (property.CanWrite && property.GetValue(request) != null)
                    {
                        property.SetValue(customerSite, property.GetValue(request));
                    }
                }
            }
            else
            {
                customerSite = request;
                if (customerSite.WebAlias.IsNullOrEmpty())
                {
                    customerSite.WebAlias = customerSite.CustomerID.ToString();
                }
                if (customerSite.WebAlias.IsNotNullOrEmpty() && !IsWebAliasAvailable(customerSite.CustomerID, customerSite.WebAlias))
                {
                    return(customerSite);
                }
            }

            // Update the data
            SetCustomerSite(customerSite);

            // Return the modified request we used to update the data
            return(customerSite);
        }
        public SetCustomerSiteRequest(CustomerSite request)
        {
            CustomerID   = request.CustomerID;
            WebAlias     = request.WebAlias;
            FirstName    = request.FirstName;
            LastName     = request.LastName;
            Company      = request.Company;

            Email        = request.Email;
            Phone        = request.PrimaryPhone;
            Phone2       = request.SecondaryPhone;
            Fax          = request.Fax;

            if (request.Address != null)
            {
                Address1 = request.Address.Address1;
                Address2 = request.Address.Address2;
                City     = request.Address.City;
                State    = request.Address.State;
                Zip      = request.Address.Zip;
                Country  = request.Address.Country;
            }

            Notes1       = request.Notes1;
            Notes2       = request.Notes2;
            Notes3       = request.Notes3;
            Notes4       = request.Notes4;
        }
示例#3
0
        public static CustomerSite GetCustomerSiteRealTime(int customerID)
        {
            var site = new CustomerSite();

            // The GetCustomerSite method currently throws an exception if no customer site record exists for the customer
            // We will set the site for this customer in the Catch and get the site again if this is the case
            try
            {
                var apiCustomerSite = ExigoDAL.WebService().GetCustomerSite(new GetCustomerSiteRequest {
                    CustomerID = customerID
                });

                site = (CustomerSite)apiCustomerSite;
            }
            catch (Exception)
            {
                // Do Nothing
            }

            return(site);
        }
示例#4
0
 public static CustomerSite SetCustomerSite(CustomerSite request)
 {
     Exigo.WebService().SetCustomerSite(new SetCustomerSiteRequest(request));
     return(request);
 }
        public JsonNetResult UpdateWebsiteCompany(CustomerSite customersite)
        {
            Exigo.UpdateCustomerSite(new CustomerSite
            {
                CustomerID = Identity.Customer.CustomerID,
                Company = customersite.Company,
                FirstName = Identity.Customer.FirstName,
                LastName = Identity.Customer.LastName

            });

            var html = string.Format("{0}", customersite.Company);

            return new JsonNetResult(new
            {
                success = true,
                action = "UpdateWebsiteCompany",
                html = html
            });
        }
示例#6
0
        public static CustomerSite GetCustomerSite(int customerID)
        {
            try
            {
                dynamic site;
                var     customerSite = new CustomerSite();

                //Get the raw data
                using (var context = ExigoDAL.Sql())
                {
                    site = context.Query(@"
                            SELECT
	                            cs.CustomerID
	                            ,cs.WebAlias
	                            ,cs.FirstName
	                            ,cs.LastName
	                            ,cs.Company
	                            ,cs.Email
	                            ,cs.Phone
	                            ,cs.Phone2                                
	                            ,cs.Address1
	                            ,cs.Address2
	                            ,cs.City
	                            ,cs.State
	                            ,cs.Zip
	                            ,cs.Country
	                            ,cs.Fax
	                            ,cs.Notes1
	                            ,cs.Notes2
	                            ,cs.Notes3
	                            ,cs.Notes4

                            FROM
	                            CustomerSites cs

                            WHERE
	                            cs.CustomerID = @customerid                      
                            ", new
                    {
                        customerid = customerID
                    }).FirstOrDefault();

                    if (site == null)
                    {
                        return(customerSite);
                    }

                    // Map the data to the model (done this way to populate the Address object correctly)
                    customerSite.CustomerID          = site.CustomerID;
                    customerSite.WebAlias            = site.WebAlias;
                    customerSite.FirstName           = site.FirstName;
                    customerSite.LastName            = site.LastName;
                    customerSite.Company             = site.Company;
                    customerSite.Email               = site.Email;
                    customerSite.PrimaryPhone        = site.Phone;
                    customerSite.SecondaryPhone      = site.Phone2;
                    customerSite.Address.AddressType = AddressType.Other;
                    customerSite.Address.Address1    = site.Address1;
                    customerSite.Address.Address2    = site.Address2;
                    customerSite.Address.City        = site.City;
                    customerSite.Address.State       = site.State;
                    customerSite.Address.Zip         = site.Zip;
                    customerSite.Address.Country     = site.Country;
                    customerSite.Fax    = site.Fax;
                    customerSite.Notes1 = site.Notes1;
                    customerSite.Notes2 = site.Notes2;
                    customerSite.Notes3 = site.Notes3;
                    customerSite.Notes4 = site.Notes4;
                }

                return(customerSite);
            }
            catch (Exception exception)
            {
                if (exception.Message == "CustomerSite not found\n")
                {
                    return(new CustomerSite());
                }
                else
                {
                    throw exception;
                }
            }
        }
        public static CustomerSite UpdateCustomerSite(CustomerSite request)
        {
            // There is no way to update the customer site with the web service - it only allows you to set all the fields.
            // Essentially, it's an all-or-none approach.
            // This method will let us update only the fields we want to update.

            // If the customer site passed is null, or we don't have the CustomerID set, stop here.
            if (request == null || request.CustomerID == 0) return request;

            // First, get the existing customer's site info
            var customerSite = GetCustomerSite(request.CustomerID);
            if (customerSite != null)
            {
                // Determine if the web alias has changed between the request and the existing data.
                // If it isn't available, set the requested web alias to null so we don't attempt to update it.
                if (request.WebAlias.IsNullOrEmpty())
                {
                    request.WebAlias = customerSite.WebAlias;
                }
                else if (request.WebAlias.ToUpper() != customerSite.WebAlias.ToUpper() && !IsWebAliasAvailable(request.CustomerID, request.WebAlias))
                {
                    request.WebAlias = null;
                }

                // Reflect each property and populate it if the requested value is not null.
                var customerSiteType = customerSite.GetType();
                var address = customerSite.Address;
                foreach (var property in customerSiteType.GetProperties())
                {
                    if (property.CanWrite && property.GetValue(request) != GlobalUtilities.GetDefault(property.PropertyType))
                    {
                        property.SetValue(customerSite, property.GetValue(request));
                    }
                }

                // Reflect the address separately
                customerSite.Address = address;
                var addressType = customerSite.Address.GetType();
                foreach (var property in addressType.GetProperties())
                {
                    if (property.CanWrite && property.GetValue(request.Address) != GlobalUtilities.GetDefault(property.PropertyType))
                    {
                        property.SetValue(customerSite.Address, property.GetValue(request.Address));
                    }
                }
            }
            else
            {
                customerSite = request;
                if (customerSite.WebAlias.IsNullOrEmpty())
                {
                    customerSite.WebAlias = customerSite.CustomerID.ToString();
                }
                if (customerSite.WebAlias.IsNotNullOrEmpty() && !IsWebAliasAvailable(customerSite.CustomerID, customerSite.WebAlias))
                {
                    return customerSite;
                }
            }

            // Update the data
            SetCustomerSite(customerSite);

            // Return the modified request we used to update the data
            return customerSite;
        }
 public static CustomerSite SetCustomerSite(CustomerSite request)
 {
     Exigo.WebService().SetCustomerSite(new SetCustomerSiteRequest(request));
     return request;
 }