コード例 #1
0
ファイル: frmMyEstates.cs プロジェクト: Almedin158/eHousing
        private async void frmMyEstates_Load(object sender, EventArgs e)
        {
            dgvMyEstates.RowTemplate.Height = 90;
            var request = new EstateUpsertRequest
            {
                UserId = _Id
            };
            var result = await estateService.Get <List <MEstate> >(request);

            dgvMyEstates.DataSource = result;
        }
コード例 #2
0
        public async Task RentEstate()
        {
            if (Estate.IsOccupied == true)
            {
                UserDialogs.Instance.Alert("Sadly, the estate is already occupied", "Payment failed", "OK");
                return;
            }


            if (ExpMonth == null || ExpMonth == "" || ExpYear == null || ExpYear == "" || Number == null || Number == "" || Cvc == null || Cvc == "")
            {
                UserDialogs.Instance.Alert("You have to fill all fields!", "Payment failed", "OK");
                return;
            }
            if (ExpMonth != null || ExpMonth != "" || ExpYear != null || ExpYear != "" || Number != null || Number != "" || Cvc != null || Cvc != "")
            {
                if (!IsDigitsOnly(ExpMonth) || !IsDigitsOnly(ExpMonth) || !IsDigitsOnly(Number) || !IsDigitsOnly(Cvc))
                {
                    UserDialogs.Instance.Alert("You can't use letters!", "Payment failed", "OK");
                    return;
                }
            }
            CreditCardModel          = new CreditCard();
            CreditCardModel.ExpMonth = Convert.ToInt64(ExpMonth);
            CreditCardModel.ExpYear  = Convert.ToInt64(ExpYear);
            CreditCardModel.Number   = Number;
            CreditCardModel.Cvc      = Cvc;
            CancellationTokenSource tokenSource = new CancellationTokenSource();
            CancellationToken       token       = tokenSource.Token;

            try
            {
                UserDialogs.Instance.ShowLoading("Payment processing ...");
                await Task.Run(async() =>
                {
                    var Token = CreateTokenAsync();
                    Console.Write(Estate.EstateName + "Token :" + Token);
                    if (Token.ToString() != null)
                    {
                        IsTransectionSuccess = await MakePaymentAsync(Token.Result);
                    }
                    else
                    {
                        UserDialogs.Instance.Alert("Bad card credentials", null, "OK");
                    }
                });
            }
            catch (Exception ex)
            {
                UserDialogs.Instance.HideLoading();
                UserDialogs.Instance.Alert(ex.Message, null, "OK");
                Console.Write(Estate.EstateName + ex.Message);
            }
            finally
            {
                if (IsTransectionSuccess)
                {
                    var date    = DateTime.Now;
                    var request = new EstateStatusUpsertRequest()
                    {
                        EstateId      = Estate.EstateId,
                        UserId        = SignedInUser.User.UserId,
                        OccupiedSince = DateTime.Now,
                        OccupiedTill  = date.AddMonths(months),
                        Months        = months,
                        TotalPrice    = Estate.Price * months
                    };
                    await estateStatusService.Insert <MEstateStatus>(request);

                    await Navigation.PushAsync(new MyEstatesPage());

                    Console.Write(Estate.EstateName + "Payment Successful");

                    var req = new EstateUpsertRequest
                    {
                        EstateDescription = Estate.EstateDescription,
                        PetsAllowed       = Estate.PetsAllowed.Value,
                        CreationDate      = Estate.CreationDate,
                        EstateName        = Estate.EstateName,
                        EstateTypeId      = Estate.EstateTypeId,
                        FloorSpace        = Estate.FloorSpace,
                        Image             = Estate.Image,
                        NumberOfRooms     = Estate.NumberOfRooms,
                        Price             = Estate.Price,
                        StreetId          = Estate.StreetId,
                        UserId            = Estate.UserId,

                        IsOccupied = true,
                    };
                    await estateService.Update <MEstate>(Estate.EstateId, req);

                    UserDialogs.Instance.HideLoading();
                }
                else
                {
                    UserDialogs.Instance.HideLoading();
                    //UserDialogs.Instance.Alert("Oops, something went wrong", "Payment failed", "OK");
                    Console.Write(Estate.EstateName + "Payment Failure ");
                }
            }
        }