Exemplo n.º 1
0
 public Custommer(int Id, int Cpr, string Name, Account.Account account, CreditScore.CreditScore creditScore, Address.Address address)
 {
     this.id          = Id;
     this.cpr         = Cpr;
     this.name        = Name;
     this.account     = account;
     this.creditScore = creditScore;
     this.address     = address;
 }
Exemplo n.º 2
0
 public void setAddress(Address.Address address)
 {
     this.address = address;
 }
Exemplo n.º 3
0
        /* a method that create shipment and return [0] tracking pin, [1] self link, [2] label link */
        public string[] CreateShipment(Address.Address address, Package package)
        {
            // set error to false
            Error = false;

            // string uri = "https://ct.soa-gw.canadapost.ca/rs/" + CUSTOMER_NUMBER + '/' + CUSTOMER_NUMBER + "/shipment";
            string uri = "https://soa-gw.canadapost.ca/rs/" + CUSTOMER_NUMBER + '/' + CUSTOMER_NUMBER + "/shipment";

            // create http post request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

            request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(USER_ID + ':' + PASSWORD)));
            request.Method      = "POST";
            request.ContentType = "application/vnd.cpc.shipment-v8+xml";
            request.Accept      = "application/vnd.cpc.shipment-v8+xml";

            string textXml =
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<shipment xmlns=\"http://www.canadapost.ca/ws/shipment-v8\">" +
                "<group-id>" + DateTime.Today.ToString("yyyyMMdd") + "</group-id>" +
                "<requested-shipping-point>L5J4S7</requested-shipping-point>" +
                "<delivery-spec>";
            string serviceCode;

            switch (package.Service)
            {
            case "Regular Parcel":
                serviceCode = "DOM.RP";
                break;

            case "Xpresspost":
                serviceCode = "DOM.XP";
                break;

            case "Priority":
                serviceCode = "DOM.PC";
                break;

            default:
                serviceCode = "DOM.EP";
                break;
            }
            textXml +=
                "<service-code>" + serviceCode + "</service-code>" +
                "<sender>" +
                "<company>Ashlin BPG Marketing</company>" +
                "<contact-phone>(905) 855-3027</contact-phone>" +
                "<address-details>" +
                "<address-line-1>2351 Royal Windsor Dr</address-line-1>" +
                "<city>Mississauga</city>" +
                "<prov-state>ON</prov-state>" +
                "<country-code>CA</country-code>" +
                "<postal-zip-code>L5J4S7</postal-zip-code>" +
                "</address-details>" +
                "</sender>" +
                "<destination>" +
                "<name>" + address.Name + "</name>" +
                "<address-details>" +
                "<address-line-1>" + address.Address1 + "</address-line-1>";
            if (address.Address2 != "")
            {
                textXml += "<address-line-2>" + address.Address2 + "</address-line-2>";
            }
            textXml +=
                "<city>" + address.City + "</city>" +
                "<prov-state>" + address.State + "</prov-state>" +
                "<country-code>CA</country-code>" +
                "<postal-zip-code>" + address.PostalCode + "</postal-zip-code>" +
                "</address-details>" +
                "</destination>" +
                "<parcel-characteristics>" +
                "<weight>" + Math.Round(package.Weight, 4) + "</weight>" +
                "<dimensions>" +
                "<length>" + package.Length + "</length>" +
                "<width>" + package.Width + "</width>" +
                "<height>" + package.Height + "</height>" +
                "</dimensions>" +
                "</parcel-characteristics>" +
                "<print-preferences>" +
                "<output-format>4x6</output-format>" +
                "</print-preferences>" +
                "<preferences>" +
                "<show-packing-instructions>true</show-packing-instructions>" +
                "</preferences>" +
                "<settlement-info>" +
                "<contract-id>" + CONTRACT_NUMBER + "</contract-id>" +
                "<intended-method-of-payment>Account</intended-method-of-payment>" +
                "</settlement-info>" +
                "</delivery-spec>" +
                "</shipment>";


            // turn request string into a byte stream
            byte[] postBytes = Encoding.UTF8.GetBytes(textXml);

            // send request
            using (Stream requestStream = request.GetRequestStream())
                requestStream.Write(postBytes, 0, postBytes.Length);

            // get the response from the server
            HttpWebResponse response;

            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException wex)
            {
                // set error to true
                Error = true;

                // the case if it is a bad request -> return the error message
                using (HttpWebResponse errorResponse = (HttpWebResponse)wex.Response)
                    using (StreamReader reader = new StreamReader(errorResponse.GetResponseStream()))
                        ErrorMessage = reader.ReadToEnd();

                return(null);
            }

            string result;

            using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
                result = streamReader.ReadToEnd();

            // get tracking pin, refund link and label link
            string[] returnString = new string[3];
            doc.LoadXml(result);

            // get namespace
            var xmlns = doc.DocumentElement.Attributes["xmlns"];
            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(doc.NameTable);

            namespaceManager.AddNamespace("ns", xmlns.Value);

            // getting tracking pin
            XmlNode node = doc.SelectSingleNode("/ns:shipment-info", namespaceManager);

            returnString[0] = node["tracking-pin"].InnerText;

            // self and label links
            node = doc.SelectSingleNode("/ns:shipment-info/ns:links", namespaceManager);
            foreach (XmlNode child in node)
            {
                if (child.Attributes["rel"].Value == "self")
                {
                    returnString[1] = child.Attributes["href"].Value;
                }
                else if (child.Attributes["rel"].Value == "label")
                {
                    returnString[2] = child.Attributes["href"].Value;
                }
            }

            return(returnString);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a new instance of class Student by asking all the required fields to the user
        /// </summary>
        /// <returns>student</returns>
        public Student CreateStudent()
        {
            Student student;

breakOutStud:         // Going back to this line if one of the student's information has not a correct format/value.

            // Required fields to create a student (part 1) //
            // First name
            Console.WriteLine("Please enter the student's first name:");
            string firstName = Console.ReadLine();

            // Last name
            Console.WriteLine("Please enter the student's last name:");
            string lastName = Console.ReadLine();

            // Student number
            Console.WriteLine("Please enter the student number:");
            string studentNumber = Console.ReadLine();

            // Age
            int age;

            while (true)
            {
                Console.WriteLine("Please enter the student's age:");
                string ageString = Console.ReadLine();
                if (int.TryParse(ageString, out int result))
                {
                    age = result;
                    break;
                }
                else
                {
                    Console.WriteLine("Error! This is not an integer number. Please try again.");
                }
            }
            // Every mandatory fields is filled, we can try to create an instance of Student
            try
            {
                student = new Student(firstName, lastName, studentNumber, age);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message); // In case of problem diplay the error message
                goto breakOutStud;             // And go back to the beginning of this method
            }
            // End of part 1 //
            // Address part //
            Address.Address addressInfos;
breakOutAddress:         // Going back to this line if one of the address information has not a correct format/value.

            // Address number
            int addressNum;

            while (true)
            {
                Console.WriteLine("Please enter the student's address number:");
                string addressNumString = Console.ReadLine();
                if (int.TryParse(addressNumString, out int result))
                {
                    addressNum = result;
                    break;
                }
                else
                {
                    Console.WriteLine("Error! This is not an integer number. Please try again.");
                }
            }

            // Street
            Console.WriteLine("Please enter the student's street name:");
            string street = Console.ReadLine();

            // City
            Console.WriteLine("Please enter the student's city name:");
            string city = Console.ReadLine();

            // Country
            Console.WriteLine("Please enter the student's country:");
            string country = Console.ReadLine();

            // Try to create address instance with all the infos
            try
            {
                addressInfos = new Address.Address(addressNum, street, city, country);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message); // In case of problem, display the error message
                goto breakOutAddress;          // And go back to the beginning of address part
            }

            student.AddressInfos = addressInfos;
            // End of address part //

            // Scores array part //
            int choice; int[] scores;

            while (true)
            {
                Console.WriteLine("You have 2 options to enter the student's score array:\n\t" +
                                  "1. Entering the scores one by one in the array manually\n\t" +
                                  "2. Create an array with x random scores inside (you just choose 'x' value)");
                Console.Write("Please choose an option (1 or 2) > ");
                string choiceString = Console.ReadLine();
                if (int.TryParse(choiceString, out int result) && (int.Parse(choiceString) == 1 || int.Parse(choiceString) == 2))
                {
                    choice = result;
                    break;
                }
                else
                {
                    Console.WriteLine("Error! It's not a valid choice, please choose 1 or 2.");
                }
            }
            if (choice == 1)
            {
                scores = ScoresManual();
            }
            else
            {
                scores = ScoresAuto();
            }
            student.Scores = scores;
            // End of scores array part //
            // Every fields is filled, we can return the student
            return(student);
        }
Exemplo n.º 5
0
 public Weather(UnitType unitType, Address.Address address, IWeatherService weatherService)
 {
     _unitType = unitType;
     _address = address;
     _weatherService = weatherService;
 }