Пример #1
0
        private async void EditDetails_Click(object sender, EventArgs e)
        {
            bool hasError = false;

            if (string.IsNullOrWhiteSpace(_firstName.Text))
            {
                _firstName.Error = "Въведете Вашето име";
                hasError         = true;
            }

            if (string.IsNullOrWhiteSpace(_lastName.Text))
            {
                _lastName.Error = "Въведете Вашата фамилия";
                hasError        = true;
            }

            Role     role             = (Role)Enum.Parse(typeof(Role), _account.Properties["roles"]);
            int      selectedPosition = _positionsSpinner.SelectedItemPosition + 1;
            Position?position         =
                string.Compare(role.ToString(), Role.Player.ToString(), true) == 0 ?
                (Position)selectedPosition :
                default(Position?);

            double.TryParse(_weight.Text, out double weightValue);
            double.TryParse(_height.Text, out double heightValue);

            if (weightValue == 0 && role == Role.Player)
            {
                _weight.Error = "Това поле е задължително за играчи";
                hasError      = true;
            }

            if (heightValue == 0 && role == Role.Player)
            {
                _height.Error = "Това поле е задължително за играчи";
                hasError      = true;
            }

            if (hasError)
            {
                return;
            }

            var editMemberDetails = new EditMemberDetails
            {
                Email            = _account.Username,
                FirstName        = _firstName.Text,
                LastName         = _lastName.Text,
                PreferedPosition = position,
                Weight           = position.HasValue ? weightValue : default(double?),
                Height           = position.HasValue ? heightValue : default(double?),
                File             = _imageStream,
                DateOfBirth      = _dateOfBirth.DateTime
            };

            AndHUD.Shared.Show(this, "Промяна…");
            HttpResponseMessage httpResponse = await RestManager.EditMemberDetails(editMemberDetails);

            string response = await httpResponse.Content.ReadAsStringAsync();

            if (httpResponse.IsSuccessStatusCode)
            {
                Intent intent = new Intent(this, typeof(UserProfileActivity));
                AndHUD.Shared.Dismiss(this);
                StartActivity(intent);
            }
            else
            {
                AndHUD.Shared.Dismiss(this);
                Toast.MakeText(this, response, ToastLength.Long).Show();
            }
        }