Esempio n. 1
0
        public ActionResult List()
        {
            var currentUser = BalanceProvider.GetCurentUserBillingAccount();

            using (var dataBase = new ApplicationDbContext())
            {
                var currentUserTransactionsList = dataBase.Transactions.Where(transaction =>
                                                                              transaction.TransferFromId == currentUser.Id)
                                                  .OrderByDescending(transaction => transaction.Id)
                                                  .ToList();

                var billingAccounts = dataBase.BillingAccounts.ToList();

                var transactionListItems = currentUserTransactionsList.Select(transaction =>
                {
                    var item = new TransactionListItem
                    {
                        Date              = transaction.Date,
                        TransactionId     = transaction.Id,
                        TransactionAmount = transaction.TransactionAmount.ToString()
                    };
                    var recipientAccount   = billingAccounts.Single(account => account.Id == transaction.TransferToId);
                    item.CorrespondentName = recipientAccount.FullUserName;
                    return(item);
                });

                return(View(transactionListItems));
            }
        }
Esempio n. 2
0
        public ActionResult TransactionComplete(int?id)
        {
            if (id != null)
            {
                var billingAccount = BalanceProvider.GetCurentUserBillingAccount();
                using (var dataBase = new ApplicationDbContext())
                {
                    var curentUserTransactions = dataBase.Transactions.Where(transaction => transaction.TransferFromId == billingAccount.Id).ToList();
                    var currentTransaction     = curentUserTransactions.SingleOrDefault(transaction => transaction.Id == id);
                    if (currentTransaction != null)
                    {
                        var item = new TransactionListItem
                        {
                            TransactionId     = currentTransaction.Id,
                            Date              = currentTransaction.Date,
                            TransactionAmount = currentTransaction.TransactionAmount.ToString()
                        };

                        var billingAccounts = dataBase.BillingAccounts.ToList();
                        var correspondent   = billingAccounts.SingleOrDefault(account => account.Id.Equals(currentTransaction.TransferToId));
                        if (correspondent != null)
                        {
                            item.CorrespondentName = correspondent.FullUserName;
                            return(View(item));
                        }
                    }
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 3
0
        /// <summary>
        /// Get transaction detail
        /// </summary>
        /// <param name="transactionID">TransactionID</param>
        /// <returns>JSON Object</returns>
        public ActionResult GetTransaction(Guid transactionID)
        {
            Transaction transaction = DC.Transactions.Where(m => m.ID == transactionID).FirstOrDefault();

            if (transaction != null)
            {
                TransactionListItem item = new TransactionListItem(transaction);
                return(Json(item, JsonRequestBehavior.AllowGet));
            }

            return(Json(false, JsonRequestBehavior.AllowGet));
        }
Esempio n. 4
0
        public IEnumerable <TransactionListItem> GetTransactionsForMonth(int monthId)
        {
            using (var context = new ApplicationDbContext())
            {
                var monthEntity = context.Months.Single(e => e.Id == monthId && e.UserId == _userId);

                var transactionList = new List <TransactionListItem>();
                foreach (var paymentMade in monthEntity.PaymentsMade)
                {
                    var transaction = new TransactionListItem()
                    {
                        MonthId              = monthId,
                        MonthName            = $"{monthEntity.BeginDate.ToString("MMMM")} {monthEntity.BeginDate.ToString("yyyy")}",
                        ControllerName       = "PaymentMade",
                        TransactionId        = paymentMade.Id,
                        Type                 = paymentMade.Category.Type.ToString(),
                        CategoryOrSourceName = paymentMade.Category.Name,
                        Amount               = $"-{paymentMade.Amount.ToString("F")}",
                        TransactionDate      = paymentMade.PaymentDate
                    };
                    transactionList.Add(transaction);
                }
                foreach (var paymentReceived in monthEntity.PaymentsReceived)
                {
                    var transaction = new TransactionListItem()
                    {
                        ControllerName       = "PaymentReceived",
                        TransactionId        = paymentReceived.Id,
                        Type                 = paymentReceived.Source.Type.ToString(),
                        CategoryOrSourceName = paymentReceived.Source.Name,
                        Amount               = $"+{paymentReceived.Amount.ToString("F")}",
                        TransactionDate      = paymentReceived.PaymentDate
                    };
                    transactionList.Add(transaction);
                }
                return(transactionList.OrderByDescending(t => t.TransactionDate));
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Login([FromBody] LoginRequestDTO model)
        {
            try
            {
                int statusCode = 200;

                var result = await _signInManager.PasswordSignInAsync(model.usr, model.pass, true, lockoutOnFailure : false);

                var userID = _accountService.GetUserIDByName(model.usr);

                if (result.Succeeded)
                {
                    _autoOperationsService.ExecuteMonthlyOperations(userID);
                    var userConfigs = _accountService.GetUserConfigs(userID);

                    var categories     = _categoryService.GetAllUserCategories(userID);
                    var categoriesList = new List <CategoryDTO>();
                    foreach (var item in categories)
                    {
                        categoriesList.Add(new CategoryDTO
                        {
                            Id   = item.ID,
                            Name = item.Name,
                            IsSpendingCategory = item.IsSpendingCategory,
                            IsSystem           = item.IsSystem,
                            CreatedBy          = item.CreatedByID, //TODO check
                            Icon = item.Icon
                        });
                    }

                    var transactions     = _transactionService.GetUserTransactions(userID, DateTime.Now.Year, DateTime.Now.Month);
                    var transactionsList = new List <TransactionListItem>();
                    foreach (var transaction in transactions)
                    {
                        TransactionListItem listItem = new TransactionListItem()
                        {
                            Id         = transaction.ID.ToString(),
                            Amount     = transaction.Amount,
                            CategoryId = transaction.CategoryID,
                            IsPlaned   = transaction.IsPlaned,
                            IsSpending = transaction.IsSpending,
                            Name       = transaction.Name,
                            TransDate  = transaction.TransactionDate,
                            UserId     = transaction.UserID
                        };
                        transactionsList.Add(listItem);
                    }

                    LoginResponseDTO response = new LoginResponseDTO
                    {
                        Status       = statusCode,
                        UserSettings = userConfigs,
                        Categories   = categoriesList,
                        Transactions = transactionsList
                    };

                    return(Ok(response));
                }
                else
                {
                    statusCode = 401;
                    LoginResponseDTO erroResult = new LoginResponseDTO
                    {
                        Status = 401
                    };
                    return(Ok(erroResult));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 6
0
        private static async void GetHtmlAsync(String currency, String path, String fName)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            DateTime dateEnd   = DateTime.Now;
            DateTime dateStart = dateEnd.AddDays(-2);

            var url        = "https://srh.bankofchina.com/search/whpj/searchen.jsp";
            var httpClient = new HttpClient();
            var html       = await httpClient.GetStringAsync(url);


            var values = new Dictionary <string, string>
            {
                { "erectDate", dateStart.ToString("yyyy-MM-dd") },
                { "nothing", dateEnd.ToString("yyyy-MM-dd") },
                { "pjname", currency }
            };

            var content = new FormUrlEncodedContent(values);

            var response = await httpClient.PostAsync(url, content);

            var responseString = await response.Content.ReadAsStringAsync();

            if (responseString == null)
            {
                Console.WriteLine("Failed to connect to website");
                return;
            }

            var recCount = responseString.Substring(responseString.IndexOf("m_nRecordCount"));

            recCount = recCount.Substring(recCount.IndexOf("=") + 2, recCount.IndexOf(";") - recCount.IndexOf("=") - 2);



            var htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(responseString);

            var TransactionList = htmlDocument
                                  .DocumentNode.Descendants("table")
                                  .Where(node => node.GetAttributeValue("width", "")
                                         .Equals("640")).ToList();

            var TransactionListItems = TransactionList[0].Descendants("tr").ToList();

            String result = "";

            Console.WriteLine("Starting first page");
            foreach (var TransactionListItem in TransactionListItems)
            {
                int counter = 0;
                for (int i = 0; i < 7; i++)
                {
                    if (counter < 6)
                    {
                        result += TransactionListItem.Descendants("td").ElementAtOrDefault(i).InnerText + ",";
                        //Console.Write(TransactionListItem.Descendants("td").ElementAtOrDefault(i).InnerText + ",");
                        counter++;
                    }
                    else
                    {
                        result += TransactionListItem.Descendants("td").ElementAtOrDefault(i).InnerText + "\n";
                        //Console.WriteLine(TransactionListItem.Descendants("td").ElementAtOrDefault(i).InnerText + "\n");
                    }
                }
            }

            for (int j = 2; j <= Math.Ceiling(Double.Parse(recCount) / 20); j++)
            {
                Console.WriteLine("Starting page " + j);
                values = new Dictionary <string, string>
                {
                    { "erectDate", dateStart.ToString("yyyy-MM-dd") },
                    { "nothing", dateEnd.ToString("yyyy-MM-dd") },
                    { "pjname", currency },
                    { "page", j + "" }
                };

                content = new FormUrlEncodedContent(values);

                response = await httpClient.PostAsync(url, content);

                responseString = await response.Content.ReadAsStringAsync();

                htmlDocument = new HtmlDocument();
                htmlDocument.LoadHtml(responseString);

                TransactionList = htmlDocument
                                  .DocumentNode.Descendants("table")
                                  .Where(node => node.GetAttributeValue("width", "")
                                         .Equals("640")).ToList();

                TransactionListItems = TransactionList[0].Descendants("tr").ToList();

                bool header = true;

                foreach (var TransactionListItem in TransactionListItems)
                {
                    if (header == true)
                    {
                        header = false;
                        continue;
                    }
                    int counter = 0;
                    for (int i = 0; i < 7; i++)
                    {
                        if (counter < 6)
                        {
                            result += TransactionListItem.Descendants("td").ElementAtOrDefault(i).InnerText + ",";
                            //Console.Write(TransactionListItem.Descendants("td").ElementAtOrDefault(i).InnerText + ",");
                            counter++;
                        }
                        else
                        {
                            result += TransactionListItem.Descendants("td").ElementAtOrDefault(i).InnerText + "\n";
                            //Console.WriteLine(TransactionListItem.Descendants("td").ElementAtOrDefault(i).InnerText + "\n");
                        }
                    }
                }
            }
            fName += ".csv";
            path  += @"\" + fName;
            File.WriteAllText(path, result);
            Console.WriteLine("Finished");
        }