//
        // GET: /Transaction/

        public ActionResult Index()
        {
            CategoryManager categoryManager = new CategoryManager();
            ViewData["categories"] = categoryManager.GetAllCategories();

            return View(db.Transactions.OrderByDescending(t => t.CreateDate).ThenByDescending(t => t.Id).ToList());
        }
        //
        // GET: /Transaction/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Transaction transaction = db.Transactions.Find(id);
            if (transaction == null)
            {
                return HttpNotFound();
            }
            CategoryManager categoryManager = new CategoryManager();
            ViewData["categories"] = new SelectList(categoryManager.GetAllCategories(), "Id", "Name", transaction.CategoryId);
            return View(transaction);
        }
        //
        // GET: /Transaction/Create

        public ActionResult Create()
        {
            CategoryManager categoryManager = new CategoryManager();
            ViewData["categories"] = new SelectList(categoryManager.GetAllCategories(), "Id", "Name", 0);

            object o = HttpContext.Session["lastCreateDate"];
            DateTime date = (o == null ? DateTime.Now : (DateTime)o);
            ViewBag.LastCreateDate = date.ToString("yyyy-MM-dd");

            Transaction trans = new Transaction();
            trans.AffectsMonthlyLimit = true;

            return View(trans);
        }
Esempio n. 4
0
        public ActionResult Index(DateTime? start = null, DateTime? end = null)
        {
            if (!start.HasValue || !end.HasValue)
            { 
                start = DateTime.Now.AddDays(-1 * DateTime.Now.Day + 1).Date;
                end = start.Value.AddMonths(1).AddDays(-1);
            }

            ViewBag.StartDate = start.Value.ToString("yyyy-MM-dd");
            ViewBag.EndDate = end.Value.ToString("yyyy-MM-dd");

            TransactionManager transactionManager = new TransactionManager();
            List<Transaction> transactions = transactionManager.GetTransactionsInInterval(start.Value, end.Value);

            BudgetLimitManager limitManager = new BudgetLimitManager();
            List<BudgetLimit> limits = limitManager.GetBudgetLimitsForInterval(start.Value, end.Value);

            TotalCashManager cashManager = new TotalCashManager();
            List<TotalCash> totalCashes = cashManager.GetAllTotalCashes();

            CategoryManager categoryManager = new CategoryManager();
            List<Category> categories = categoryManager.GetAllCategories();

            BLL.Reporter reporter = new BLL.Reporter(start.Value, end.Value, transactions, limits, totalCashes, categories);
            ViewData["AverageLimitPerDay"] = String.Format(format, reporter.GetAverageLimitPerDay());
            ViewData["TotalLimit"] = String.Format(format, reporter.GetTotalLimit());
            ViewData["AverageExpensePerDay"] = String.Format(format, reporter.GetAverageExpensePerDay());
            ViewData["TotalExpense"] = String.Format(format, reporter.GetTotalExpense());
            ViewData["TotalAvailableAmount"] = reporter.GetAvailableAmount();
            ViewData["TotalAvailableAmountFormatted"] = String.Format(format, reporter.GetAvailableAmount());
            ViewData["AvailableAmountPerDay"] = String.Format(format, Math.Max(0, reporter.GetAvailableAmountPerDay()));
            ViewData["NumberOfDays"] = reporter.NumberOfDays;
            ViewData["NumberOfDaysUntilToday"] = reporter.NumberOfDaysUntilToday;

            ViewData["CurrentTotalCash"] = String.Format(format, reporter.GetCurrentTotalCash());
            ViewData["StartingTotalCash"] = String.Format(format, reporter.GetStartingTotalCash());
            ViewData["TotalCashDifferenceFormatted"] = String.Format(format, reporter.GetCurrentTotalCash() - reporter.GetStartingTotalCash());
            ViewData["TotalCashDifference"] = reporter.GetCurrentTotalCash() - reporter.GetStartingTotalCash();

            List<KeyValuePair<Category, int>> amountsByCategoryName = reporter.GetAmountsByCategoryName();
            ViewData["AmountsByCategoryName"] = amountsByCategoryName;
            ViewData["TotalAmountsForCategories"] = amountsByCategoryName.Count == 0 ? 0 : (double)amountsByCategoryName.Select(t => t.Value).Sum();

            HttpContext.Session["Reporter"] = reporter;

            return View();
        }
        public ActionResult Create(Transaction transaction)
        {
            CategoryManager categoryManager = new CategoryManager();
            ViewData["categories"] = new SelectList(categoryManager.GetAllCategories(), "Id", "Name", transaction.CategoryId);

            if (ModelState.IsValid)
            {
                if (transaction.CategoryId == 0)
                    transaction.CategoryId = null;
                db.Transactions.Add(transaction);
                db.SaveChanges();

                HttpContext.Session["lastCreateDate"] = transaction.CreateDate;

                return RedirectToAction("Index");
            }

            object o = HttpContext.Session["lastCreateDate"];
            DateTime date = (o == null ? DateTime.Now : (DateTime)o);
            ViewBag.LastCreateDate = date.ToString("yyyy-MM-dd");

            return View(transaction);
        }
        //
        // GET: /Transaction/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Transaction transaction = db.Transactions.Find(id);
            if (transaction == null)
            {
                return HttpNotFound();
            }

            CategoryManager categoryManager = new CategoryManager();
            transaction.Category = categoryManager.GetAllCategories().Find(t => t.Id == transaction.CategoryId);
            return View(transaction);
        }
        public ProjectCategoryModel()
        {
            _projectManager = new ProjectManager(GKSFactory.GetProjectManager());
            _categoryManager = new CategoryManager(GKSFactory.GetCategoryManager());

            _allCategories = _categoryManager.GetCategories().ToList();

            AddCategoryButtonClicked = new AddCategoryInProjet(this);
            RemoveCategoryButtonClicked = new RemoveCategoryFromProjet(this);
        }