public ActionResult Edit(Expense expense) { if (Session["UserName"] == null) { return(RedirectToAction("Login", "Authentication")); } else { List <Expense> expenseList = db.GetExpenseList(); Expense exp = expenseList.Where(a => a.ExpensesId == expense.ExpensesId).Single(); exp.Cost = expense.Cost; exp.Descriptions = expense.Descriptions; exp.Name = expense.Name; exp.ReleaseDate = expense.ReleaseDate; exp.Type = expense.Type; db.SaveChanges(); List <ListExpenseVM> listVM = new List <ListExpenseVM>(); foreach (Expense e in db.GetExpenseList()) { ListExpenseVM lVM = new ListExpenseVM(); lVM.expense = e; listVM.Add(lVM); } return(RedirectToAction("List", "Expense")); } }
public ActionResult List() { if (Session["UserName"] == null) { return(RedirectToAction("Login", "Authentication")); } else { List <Expense> expenseList = db.GetExpenseList(); string currentUser = Session["UserId"].ToString(); int uid = Int32.Parse(currentUser); var expense = expenseList.Where(a => a.UserId == uid).OrderByDescending(a => a.ReleaseDate).ToList(); ListExpenseVM listExpenseVM = new ListExpenseVM(); listExpenseVM.expenseList = expense; return(View("List", listExpenseVM)); } }