Beispiel #1
0
        private void UpdateCard(bool isAdding)
        {
            var url = "api/bonuscard/update";

            var typeParam = isAdding ? 1.ToString() : 0.ToString();

            var qryParams = $"number={_card.CardNumber}&value={this.tbBonusValue.Text}&type={typeParam}";

            url = $"{url}?{qryParams}";

            var parametrers = new PaymentCardParamsModel
            {
                CardNumber = _card.CardNumber,
                NewValue   = _card.Balance.Value.ToString(),
                Type       = typeParam
            };

            var postParams = JsonConvert.SerializeObject(parametrers);

            var response = new CardApiClient().Post(url, postParams);

            if (response.IsSuccessStatusCode)
            {
                MessageBox.Show("Success");
            }
            else
            {
                MessageBox.Show("Error Code" + response.StatusCode + " : Message - " + response.ReasonPhrase);
            }
        }
Beispiel #2
0
        private void AddNewClient()
        {
            var url = "api/client";

            var qryParams = $"firstName={_card.FirstName}&lastName={_card.LastName}&phone={_card.PhoneNumber}";

            url = $"{url}?{qryParams}";

            var parametrers = new AddParamsModel
            {
                FirstName   = _card.FirstName,
                LastName    = _card.LastName,
                PhoneNumber = _card.PhoneNumber
            };

            var postParams = JsonConvert.SerializeObject(parametrers);

            var response = new CardApiClient().Post(url, postParams);

            if (response.IsSuccessStatusCode)
            {
                MessageBox.Show("Success");

                Close();
            }
            else
            {
                MessageBox.Show("Error Code" + response.StatusCode + " : Message - " + response.ReasonPhrase);
            }
        }
Beispiel #3
0
        private void btnCreateCard_Click(object sender, RoutedEventArgs e)
        {
            var url = "api/bonuscard";

            var qryParams = $"phone={_card.PhoneNumber}&expdate={this.dpExpDate.SelectedDate.Value:dd.MM.yyyy}";

            url = $"{url}?{qryParams}";

            var parametrers = new CreateParamsModel
            {
                PhoneNumber    = _card.PhoneNumber,
                ExpirationDate = this.dpExpDate.SelectedDate.Value.ToString("dd.MM.yyyy")
            };

            var postParams = JsonConvert.SerializeObject(parametrers);

            var response = new CardApiClient().Post(url, postParams);

            if (response.IsSuccessStatusCode)
            {
                MessageBox.Show("Success");

                Close();
            }
            else
            {
                MessageBox.Show("Error Code" + response.StatusCode + " : Message - " + response.ReasonPhrase);
            }
        }
        private void SearchClient()
        {
            var searchInput = isSearchByNumber
                ? txtCardNumber.Text.Trim()
                : txtPhoneNumber.Text.Trim();

            if (string.IsNullOrEmpty(searchInput))
            {
                // return Validation Message
                return;
            }

            if (!searchInput.All(Char.IsDigit))
            {
                // return Validation Message
                return;
            }

            var url = isSearchByNumber
                ? "api/bonuscard/getbynumber/"
                : $"api/bonuscard/getbyphone/";

            url = $"{url}{searchInput}";

            var response = new CardApiClient().Get(url);

            if (response.IsSuccessStatusCode)
            {
                if (isSearchByNumber)
                {
                    var bonusCard  = response.Content.ReadAsAsync <BonusCard>().Result;
                    var bonusCards = new List <BonusCard> {
                        bonusCard
                    };
                    grdClients.ItemsSource = bonusCards;
                }
                else
                {
                    var bonusCards = response.Content.ReadAsAsync <IEnumerable <BonusCard> >().Result;

                    grdClients.ItemsSource = bonusCards;
                }
            }
            else
            {
                MessageBox.Show("Error Code" + response.StatusCode + " : Message - " + response.ReasonPhrase);
            }
        }