Example #1
0
 public ActionResult EditExpense(ExpenseManagingViewModel item)
 {
     if (ModelState.IsValid)
     {
         var expenseRepository = new ExpenseRepository();
         expenseRepository.EditExpense(item.ExpenseItem);
         return(RedirectToAction("ExpenseManager"));
     }
     return(View(item));
 }
Example #2
0
        public ActionResult SaveEditExpense(Guid id, string store, string category, string amount, string date, bool sharedExpense)
        {
            var accountId = HttpContext.Session.Get <long>(SessionHelper.SessionKeyAccountId);

            if (accountId == default)
            {
                return(RedirectToAction("Login", "Account", new { id = LoginHelper.BudgetApp }));
            }


            if (id == default || id == Guid.Empty)
            {
                return(Json(new { status = false, message = "ERROR: Please refresh the page." }));
            }
            if (string.IsNullOrWhiteSpace(store))
            {
                return(Json(new { status = false, message = "Store is required" }));
            }
            if (string.IsNullOrWhiteSpace(category))
            {
                return(Json(new { status = false, message = "Category is required" }));
            }
            if (string.IsNullOrWhiteSpace(amount))
            {
                return(Json(new { status = false, message = "Amount is required" }));
            }
            if (!decimal.TryParse(amount, out decimal amountValue))
            {
                return(Json(new { status = false, message = "Amount is required" }));
            }
            if (string.IsNullOrWhiteSpace(date))
            {
                return(Json(new { status = false, message = "Date is required" }));
            }
            if (!DateTime.TryParse(date, out DateTime dateValue))
            {
                return(Json(new { status = false, message = "Date is required" }));
            }

            var storeId    = StoreHelper.GetOrAddStoreId(store);
            var categoryId = CategoryHelper.GetCategoryId(category);

            if (sharedExpense)
            {
                var sharedAccountId = AccountHelper.GetSharedAccountId(accountId);
                ExpenseRepository.EditExpense(id, sharedAccountId, storeId, categoryId, amountValue, dateValue);
            }
            else
            {
                ExpenseRepository.EditExpense(id, accountId, storeId, categoryId, amountValue, dateValue);
            }
            return(Json(new { status = true, message = "Expense Editted" }));
        }