Example #1
0
        private void LoadActivations()
        {
            try
            {
                HttpClient client = InitializeClient();

                string              result;
                dynamic             items;
                HttpResponseMessage response;

                //Call the API
                response = client.GetAsync("Activation").Result;

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    //Proces response
                    result = response.Content.ReadAsStringAsync().Result;

                    //Put json into the activation list
                    items       = (JArray)JsonConvert.DeserializeObject(result);
                    activations = items.ToObject <ActivationList>();
                }
                else
                {
                    throw new Exception("Error: " + response.ReasonPhrase);
                }
            }
            catch (Exception ex)
            {
                lblQuestion.Text = ex.Message;
            }
        }
Example #2
0
 public string GetActivationListAsString()
 {
     if (ActivationList.Count == 1)
     {
         return(ActivationList.First().ToString());
     }
     else if (ActivationList.Count == 2)
     {
         return($"{ActivationList.First()}, and {ActivationList.Last()}");
     }
     else if (ActivationList.Count > 2)
     {
         string numbers = "";
         for (int i = 0; i < ActivationList.Count; i++)
         {
             if (i == ActivationList.Count - 1)
             {
                 numbers += $"and {ActivationList[i]}";
             }
             else
             {
                 numbers += $"{ActivationList[i]}, ";
             }
         }
         return(numbers);
     }
     return(string.Empty);
 }
Example #3
0
        // GET: api/Activation
        public IEnumerable <Activation> Get()
        {
            ActivationList activations = new ActivationList();

            activations.Load();
            return(activations);
        }
        private void BtnDelete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Remove the entry from the database via the SL
                activations = new ActivationList();
                LoadActivations();

                Activation activation = new Activation();
                activation = activations.FirstOrDefault(a => a.QuestionId == questions[cboQuestions.SelectedIndex].Id);

                HttpClient          client   = InitializeClient();
                HttpResponseMessage response = client.DeleteAsync("Activation/" + activation.Id).Result;

                //Update the screen
                dtpEndDate.SelectedDate   = null;
                dtpStartDate.SelectedDate = null;
                txtActivationCode.Text    = String.Empty;
                lblStatus.Content         = "Activation Removed";
            }
            catch (Exception ex)
            {
                lblStatus.Content = ex.Message;
            }
        }
        private void CboQuestions_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                //Clear status strip
                lblStatus.Content = String.Empty;


                activations = new ActivationList();
                LoadActivations();

                Activation activation = new Activation();
                activation = activations.FirstOrDefault(a => a.QuestionId == questions[cboQuestions.SelectedIndex].Id);

                if (activation != null)
                {
                    //Activation found
                    dtpEndDate.SelectedDate   = activation.EndDate;
                    dtpStartDate.SelectedDate = activation.StartDate;
                    txtActivationCode.Text    = activation.ActivationCode;
                }
                else
                {
                    dtpEndDate.SelectedDate   = null;
                    dtpStartDate.SelectedDate = null;
                    txtActivationCode.Text    = String.Empty;
                }
            }
            catch (Exception ex)
            {
                lblStatus.Content = ex.Message;
            }
        }
Example #6
0
        public void LoadTest()
        {
            ActivationList activations = new ActivationList();

            activations.Load();

            int expected = 3;
            int actual   = activations.Count;

            Assert.AreEqual(expected, actual);
        }
Example #7
0
        public void DeleteTest()
        {
            //Load all activations and then get the activation
            ActivationList activations = new ActivationList();

            activations.Load();
            Activation activation = activations.FirstOrDefault(a => a.ActivationCode == "updte");

            int rowsAffected = activation.Delete();

            Assert.IsTrue(rowsAffected == 1);
        }
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //TO DO: VALIDATE THE USER DATA
                bool validData = true;
                activations = new ActivationList();
                LoadActivations();


                string activationcode = txtActivationCode.Text.ToLower();
                if (activationcode.Length != 5)
                {
                    validData = false;
                    throw new Exception("Activation code must be 5 characters.");
                }
                else if (activations.Any(a => a.ActivationCode == activationcode))
                {
                    validData = false;
                    throw new Exception("This activation code is already in use.");
                }
                else if (dtpEndDate.SelectedDate == null)
                {
                    validData = false;
                    throw new Exception("You must select an End Date.");
                }
                else if (dtpStartDate.SelectedDate == null)
                {
                    validData = false;
                    throw new Exception("You must select an Start Date.");
                }



                if (validData)
                {
                    SaveActivation();
                }

                else
                {
                    throw new Exception("Invalid data.");
                }
            }
            catch (Exception ex)
            {
                lblStatus.Content = ex.Message;
            }
        }
Example #9
0
        public void UpdateTest()
        {
            //Load all activations and then get the activation
            ActivationList activations = new ActivationList();

            activations.Load();
            Activation activation = activations.FirstOrDefault(a => a.QuestionId == Guid.Empty);

            //Change the properties
            activation.ActivationCode = "updte";

            //Update the activation
            int rowsAffected = activation.Update();


            Assert.IsTrue(rowsAffected == 1);
        }
Example #10
0
        protected MemoryNodeImpl(int id)
        {
            _id = id;

            _successors = new ActivationList <T>();
        }