Exemplo n.º 1
0
 public DetailedTransactionView(RefinedTransactions obj)
 {
     TransactionDetails = obj;
     InitializeComponent();
     this.BindingContext = obj;
     LoadDetails();
 }
        public async Task GetTransactionsByNuban(string nuban, string currencyCode)
        {
            try
            {
                var selectedMonthIndex = DateTime.Now.Month;
                var currentYear        = DateTime.Now.Year;
                var daysInMonth        = DateTime.DaysInMonth(currentYear, selectedMonthIndex);
                var startDate          = new DateTime(currentYear, selectedMonthIndex, 1);
                var endDate            = new DateTime(currentYear, selectedMonthIndex, daysInMonth);

                CheckConnectivity();
                if (string.IsNullOrEmpty(nuban))
                {
                    return;
                }
                IsTransactionLoading        = true;
                TransactionMessage          = string.Empty;
                ShowTransactionErrorMessage = false;
                CustomerTransactions.Clear();
                var apirequest = new ApiRequest();


                string url     = $"Transaction/GetUserTransactionsByRange?userId={GlobalStaticFields.Customer.Email}&StartDate={startDate.ToString("MM-dd-yyyy")}&EndDate={endDate.ToString("MM-dd-yyyy")}";
                var    request = await apirequest.GetWithSwitchId(GlobalStaticFields.Customer.Email, "", URLConstants.SwitchApiLiveBaseUrl, url, "BankAccounts");

                if (request.IsSuccessStatusCode)
                {
                    var jsonString = await request.Content.ReadAsStringAsync();

                    jsonString = jsonString.JsonCleanUp();
                    transactions.Clear();
                    var jobj = JsonConvert.DeserializeObject <APIResponse <List <GetStatements> > >(jsonString);
                    if (jobj.Status)
                    {
                        var filt = jobj.Data.Where(c => c.FromAccount == nuban || c.ToAccount == nuban).OrderByDescending(c => c.ID).ToList().Take(3);

                        foreach (var rec in filt)
                        {
                            var amt          = Convert.ToDouble(rec.Amount).ToString("##, ###.##");
                            var refinedTrans = new RefinedTransactions
                            {
                                CategoryName     = rec.CategoryName,
                                BeneficiaryName  = rec.BeneficiaryName,
                                Amount           = rec.IsBeneficiary == true ? $"{Utilities.GetCurrency(currencyCode)} {amt}" : $"{Utilities.GetCurrency(currencyCode)} {amt}",
                                AmountColor      = rec.IsBeneficiary == true ? Color.Green : Color.Red,
                                ReferenceID      = rec.ReferenceID,
                                TransactionDate  = rec.TransactionDate.ToString("d MMM"),
                                PaymentReference = rec.PaymentReference
                            };
                            transactions.Add(refinedTrans);
                        }

                        CustomerTransactions.ReplaceRange(transactions);
                        if (CustomerTransactions.Count > 0)
                        {
                            TransactionMessage = "";
                        }
                    }
                    else
                    {
                        ShowTransactionErrorMessage = true;
                        TransactionMessage          = "No Transaction Found";
                    }
                }
                else
                {
                    var content = await request.Content.ReadAsStringAsync();
                }
            }
            catch (WebException e)
            {
            }
            catch (Exception ex)
            {
            }
            finally
            {
                IsTransactionLoading = false;
            }
        }