Exemplo n.º 1
0
        public async Task Claim(int rotationId)
        {
            var answer = await Application.Current.MainPage.DisplayAlert("Confirm", $"Claim this rotation?", "Yes", "No");

            if (answer)
            {
                Helper helper   = new Helper();
                var    isLocked = await helper.IsLocked();

                if (isLocked)
                {
                    await Application.Current.MainPage.DisplayAlert("Warning", "No rotations can be placed at this time, some changes are being made. Plese try again later.", "OK");
                }
                else
                {
                    Model.Buy buy = new Model.Buy()
                    {
                        Item   = BuyItem.Rotation,
                        ItemId = rotationId,
                        UserId = APIService.User.UserId
                    };
                    try {
                        await _usersApi.Buy <string>(buy);

                        await Application.Current.MainPage.DisplayAlert("Success", "You have claimed the rotation successfully!", "OK");
                    }
                    catch {
                        await Application.Current.MainPage.DisplayAlert("Oops", $"You have already claimed this rotation!", "OK");
                    }
                }
            }
        }
        public async Task Subscribe(int subId, decimal price)
        {
            var answer = await Application.Current.MainPage.DisplayAlert("Confirm", $"Are you sure you want to subscribe for {price}/month?", "Yes", "No");

            if (answer)
            {
                Helper helper   = new Helper();
                var    isLocked = await helper.IsLocked();

                if (isLocked)
                {
                    await Nav.PopAsync();

                    await Application.Current.MainPage.DisplayAlert("Warning", "No subscriptions can be placed at this time, some changes are being made. Plese try again later.", "OK");
                }
                else
                {
                    Model.Buy buy = new Model.Buy()
                    {
                        Item   = BuyItem.Subscription,
                        ItemId = subId,
                        UserId = APIService.User.UserId
                    };
                    try {
                        await _usersApi.Buy <string>(buy);

                        await Application.Current.MainPage.DisplayAlert("Success", "You have subscribed successfully!", "OK");
                    }
                    catch {
                        await Application.Current.MainPage.DisplayAlert("Oops", $"You are already subscribed to this subscription box!", "OK");
                    }
                }
            }
        }
Exemplo n.º 3
0
        public async Task <string> Buy <T>(Model.Buy buy)
        {
            var url = $"{_apiUrl}/{_controller}/BuyItem";

            try {
                var result = await url.WithBasicAuth(Username, Password).PostJsonAsync(buy).ReceiveString();

                return(result);
            }
            catch (FlurlHttpException ex) {
                if (ex.Call.HttpStatus == System.Net.HttpStatusCode.Unauthorized)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "Access denied!", "OK");
                }
                if (ex.Call.HttpStatus == System.Net.HttpStatusCode.Forbidden)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "Access forbidden!", "OK");
                }
                throw;
            }
        }
Exemplo n.º 4
0
        public async Task Buy()
        {
            var answer = await Application.Current.MainPage.DisplayAlert("Confirm", $"Buy '{Show.Title}' for {Show.Price}?", "Yes", "No");

            if (answer)
            {
                Helper helper   = new Helper();
                var    isLocked = await helper.IsLocked();

                if (isLocked)
                {
                    await Nav.PopAsync();

                    await Application.Current.MainPage.DisplayAlert("Warning", "No orders can be placed at this time, some changes are being made. Plese try again later.", "OK");
                }
                else
                {
                    Model.Buy buy = new Model.Buy()
                    {
                        Item   = BuyItem.Show,
                        ItemId = Show.ShowId,
                        UserId = APIService.User.UserId
                    };
                    try {
                        await _usersApi.Buy <string>(buy);

                        await Nav.PopAsync();

                        await Application.Current.MainPage.DisplayAlert("Success", "Show bought successfully", "OK");
                    }
                    catch {
                        await Nav.PopAsync();

                        await Application.Current.MainPage.DisplayAlert("Oops", $"You already bought '{Show.Title}'", "OK");
                    }
                }
            }
        }
Exemplo n.º 5
0
 public ActionResult <string> Buy(Model.Buy buy)
 {
     return(_service.BuyItem(buy));
 }