public ActionResult Edit(int?id)
 {
     if (Session["UserName"] == null)
     {
         return(RedirectToAction("Login", "Authentication"));
     }
     else
     {
         List <Expense> expenseList = db.GetExpenseList();
         Expense        expense     = expenseList.Where(a => a.ExpensesId == id).Single();
         EditExpenseVM  editVM      = new EditExpenseVM();
         editVM.expense = expense;
         return(View("Edit", editVM));
     }
 }
Esempio n. 2
0
        // GET: User
        public ActionResult Index()
        {
            if (Session["UserName"] == null)
            {
                return(RedirectToAction("Login", "Authentication"));
            }
            else
            {
                List <User>    userList    = db.GetUserList();
                List <Budget>  budgetList  = db.GetBudgetList();
                List <Expense> expenseList = db.GetExpenseList();

                string currentUser = Session["UserId"].ToString();
                int    uid         = Int32.Parse(currentUser);
                User   user        = userList.Where(a => a.UserId == uid).Single();
                //Wyświetlenie 10 ostatnio dodanych wydatków
                var expense = expenseList.Where(a => a.UserId == uid).OrderByDescending(a => a.ReleaseDate).Take(10).ToList();
                //Ostatnio dodany budżet
                Budget  lastBudget = budgetList.Where(b => b.UserId == uid).OrderByDescending(b => b.BudgetId).FirstOrDefault();
                decimal allBudgets = budgetList.Where(b => b.UserId == uid).Sum(b => b.Salary);

                //Dane do wykresu
                try
                {
                    decimal billExpense      = expenseList.Where(x => x.Type == Expense.ExpenseType.Rachunek && x.UserId == uid).Sum(x => x.Cost);
                    decimal shoppingExpense  = expenseList.Where(x => x.Type == Expense.ExpenseType.Zakupy && x.UserId == uid).Sum(x => x.Cost);
                    decimal departureExpense = expenseList.Where(x => x.Type == Expense.ExpenseType.Wyjścia && x.UserId == uid).Sum(x => x.Cost);
                    var     list             = Enum.GetValues(typeof(Expense.ExpenseType)).Cast <Expense.ExpenseType>().ToList();
                    decimal allExpense       = billExpense + shoppingExpense + departureExpense;
                    decimal _value           = allBudgets - allExpense;
                    ViewBag.Message = _value;


                    var myChart = new Chart(width: 600, height: 500)
                                  .AddTitle("Wydatki")
                                  .AddSeries(
                        name: "Wydatki",
                        chartType: "column",
                        xValue: new[] { "Rachunki", "Zakupy", "Wyjścia" },
                        yValues: new[] { billExpense, shoppingExpense, departureExpense });
                    myChart.Save("~/Content/chart.png");
                }
                catch { }

                //Przekazanie do viewmodelu
                DetailsVM detailsVM = new DetailsVM();
                detailsVM.user    = user;
                detailsVM.budget  = lastBudget;
                detailsVM.expense = expense;

                return(View("Index", detailsVM));
            }
        }