///////------------------------------------------- Establishment Actions : public ActionResult AddEstablishment(string establishmentName) { // in this instance we dont have Access to the Id's so we will only compare the stirngs client side // so we will always be creating a new Establishment var db = new ExpenseDb(); var establishment = new Establishment { EstablishmentName = establishmentName }; db.EstablishmentTBL.Add(establishment); db.SaveChanges(); // here we return an updated list of the Establishments var establishments = GetEstablishments(db); var viewModel = new ExpenseDetailsViewModel(); viewModel.Establishments = establishments; return PartialView("_EstablishmentTxt",viewModel); }
// // GET: /Report/ public ActionResult Index(int reportID) { try { var viewModel = new ExpenseDetailsViewModel(); var db = new ExpenseDb(); var establishments = GetEstablishments(db);// gets a list of Establishemnts var report = GetReportDetails(reportID, db);// gets the details of a single reports var expenses = GetReportExpenses(reportID, db); // ViewBag.ListOfEst = establishments;// this is putting a list of establishments in the View bag to then be retrieved from the JS viewModel.Establishments = establishments; viewModel.Report = report; viewModel.ListOfExpenses = expenses; if (report == null) { return View("Error"); } else { return View(viewModel); } } catch (Exception) { throw; } }
public ActionResult AddEditExpense(ExpenseDetailsViewModel viewModel) { var db = new ExpenseDb(); // get expense ID if < 0 then it is a new report if (viewModel.ExpenseInput.ExpenseID <= 0) { // this is a new expense var expense = new ExpenseDetail { DateIncurred = viewModel.ExpenseInput.DateIncurred, ReceiptEntry = viewModel.ExpenseInput.ReceiptEntry, NumberOfGuest = viewModel.ExpenseInput.NumberOfGuest, GuestNames = viewModel.ExpenseInput.GuestNames, Establishment = viewModel.ExpenseInput.Establishment, Expensecategory = viewModel.ExpenseInput.Expensecategory, Reason = viewModel.ExpenseInput.Reason, Amount = viewModel.ExpenseInput.Amount, AmountPerPerson = viewModel.ExpenseInput.AmountPerPerson, ReportID = viewModel.ExpenseInput.ReportID, Notes =viewModel.ExpenseInput.Notes }; db.ExpenseDetail.Add(expense); db.SaveChanges(); } else // it is an edit to an existing report { // update an expense //db.ExpenseDetail.Where(e => e.Id == viewModel.ExpenseInput.ExpenseID).FirstOrDefault() // var expense = db.ExpenseDetail.Find(viewModel.ExpenseInput.ExpenseID); // db.Clients.Where(c => c.Id == intClientID).FirstOrDefault() var expense = db.ExpenseDetail.Where(e => e.Id == viewModel.ExpenseInput.ExpenseID).FirstOrDefault(); expense.DateIncurred = viewModel.ExpenseInput.DateIncurred; expense.ReceiptEntry = viewModel.ExpenseInput.ReceiptEntry; expense.NumberOfGuest = viewModel.ExpenseInput.NumberOfGuest; expense.GuestNames = viewModel.ExpenseInput.GuestNames; expense.Establishment = viewModel.ExpenseInput.Establishment; expense.Expensecategory = viewModel.ExpenseInput.Expensecategory; expense.Reason = viewModel.ExpenseInput.Reason; expense.Notes = viewModel.ExpenseInput.Notes; expense.Amount = viewModel.ExpenseInput.Amount; expense.AmountPerPerson = viewModel.ExpenseInput.AmountPerPerson; expense.ReportID = viewModel.ExpenseInput.ReportID; //db.ExpenseDetail.Add(expense); when doing an update no need to do the add db.SaveChanges();// just by doing the saveChanges it knows it is an update //.ClientName = clientName; //db change tracker db.SaveChanges(); //db.Clients.Where(c => c.Id == intClientID).FirstOrDefault().ClientName = clientName; //db change tracker db.SaveChanges(); } var establishments = GetEstablishments(db);// gets a list of Establishemnts var report = GetReportDetails(viewModel.ExpenseInput.ReportID, db);// gets the details of a single reports var expenses = GetReportExpenses(viewModel.ExpenseInput.ReportID, db); // ViewBag.ListOfEst = establishments;// this is putting a list of establishments in the View bag to then be retrieved from the JS viewModel.Establishments = establishments; viewModel.Report = report; viewModel.ListOfExpenses = expenses; if (report == null) { return View("Error"); } else { return PartialView("_ExpenseDetails", viewModel); //return View("Index",viewModel); } }
public ActionResult DeleteExpense(int expenseID, int reportID) { var viewModel = new ExpenseDetailsViewModel(); var db = new ExpenseDb(); // delete expense var expense = db.ExpenseDetail.Find(expenseID); db.ExpenseDetail.Remove(expense); db.SaveChanges(); // re-render Partial var establishments = GetEstablishments(db);// gets a list of Establishemnts var report = GetReportDetails(reportID, db);// gets the details of a single reports var expenses = GetReportExpenses(reportID, db); // ViewBag.ListOfEst = establishments;// this is putting a list of establishments in the View bag to then be retrieved from the JS viewModel.Establishments = establishments; viewModel.Report = report; viewModel.ListOfExpenses = expenses; if (report == null) { return View("Error"); } else { return PartialView("_ExpenseDetails", viewModel); //return View("Index", viewModel); } }