public ActionResult EditExpenseEntry(int eid) { Entities dc = new Entities(); expensesheet Sheet = dc.expensesheets.Find(eid); if (Sheet != null) { expenseentry thisExp = Sheet.expenseentries.FirstOrDefault(); if (thisExp != null) { ExpenseEntry viewExp = new ExpenseEntry() { EmpName = thisExp.expensesheet.employee.EmpFName + thisExp.expensesheet.employee.EmpLName, ExpCategory = thisExp.ExpCategory, ExpDate = thisExp.ExpDate, ExpDollarAmt = thisExp.ExpDollarAmt, ProjName = thisExp.project.ProjName, ExpenseEntryID = thisExp.ExpEntryID, SelectedCategoryText = thisExp.ExpCategory }; return(View(viewExp)); } else { return(HttpNotFound()); } } else { return(HttpNotFound()); } }
public ActionResult ExpenseEntry(int?eid, ExpenseEntry thisExpense) { //TODO: ADD edit/view expense entry logic in here using (Entities dc = new Entities()) { DateTime d = System.DateTime.Now.StartOfWeek(DayOfWeek.Monday); ///payrollcycle pc = dc.payrollcycles.Where(a => a.PayrollCycleStart = d); var v = dc.payrollcycles.Where(a => a.PayrollCycleStart == d).FirstOrDefault(); expensesheet es = new expensesheet { EmpID = Int32.Parse(Request.Cookies["UserID"].Value), PayrollCycleID = v.PayrollCycleID, ExpSheetStatus = "In Progress", ExpSheetTotalAmt = thisExpense.ExpDollarAmt }; dc.expensesheets.Add(es); expenseentry ee = new expenseentry() { ExpSheetID = (int)es.ExpSheetID, EmpID = es.EmpID, ExpDate = thisExpense.ExpDate, ExpDollarAmt = thisExpense.ExpDollarAmt, ExpCategory = thisExpense.ExpCategory.ToString(), ProjID = thisExpense.ProjID }; dc.expenseentries.Add(ee); try { dc.SaveChanges(); return(Redirect("List")); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { //more descriptive error for validation problems Exception exception = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message1 = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); //create a new exception inserting the current one as the InnerException exception = new InvalidOperationException(message1, exception); } } //error for UI ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); throw exception; } } }
public ActionResult Deny(int?tid) { Entities dc = new Entities(); expensesheet es = dc.expensesheets.Find(tid); if (es.ExpSheetStatus != "Pending") { TempData["message"] = "Action already taken."; return(RedirectToAction("PendingApprovals")); } es.ExpSheetStatus = "Denied"; es.ExpSheetApproveTime = System.DateTime.Now; //maybe change this column? dc.Entry(es).State = System.Data.Entity.EntityState.Modified; try { dc.SaveChanges(); TempData["message"] = "Denied successfully."; return(Redirect("PendingApprovals")); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { //more descriptive error for validation problems Exception exception = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message1 = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); //create a new exception inserting the current one as the InnerException exception = new InvalidOperationException(message1, exception); } } //error for UI ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); throw exception; } }