public ActionResult Create([Bind(Include = "ExpenseId,Purpose,ExpenseDate,Amount,EmployeeName,EmployeeEmail,ApproverName,ApproverEmail,Receipt")] Contoso.Expense.Entities.Models.Expense expense) { if (ModelState.IsValid) { // Get the logged in Identity var identity = (ClaimsIdentity)User.Identity; IEnumerable <Claim> claims = identity.Claims; // As the Name claim returns Email address, using Surname & Givenname to get full name var fullName = claims.Where(c => c.Type == ClaimTypes.GivenName).FirstOrDefault().Value + " " + claims.Where(c => c.Type == ClaimTypes.Surname).FirstOrDefault().Value; // Call Azure API to get Manager details based on employee name Manager manager = GetManagerDetails(fullName); // Update the Expense instance with Manager details expense.EmployeeName = fullName; expense.EmployeeEmail = manager.EmployeeEmailAddress; expense.ApproverName = manager.ManagerName; expense.ApproverEmail = manager.ManagerEmailAddress; // Send the Expense to Azure Storage Queue so that Azure Function can pick up and email to appover(manager) WriteToExpenseQueue(expense); // Save the Expense to database db.Expenses.Add(expense); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(expense)); }
public ActionResult DeleteConfirmed(int id) { Contoso.Expense.Entities.Models.Expense expense = db.Expenses.Find(id); db.Expenses.Remove(expense); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ExpenseId,Purpose,ExpenseDate,Amount,EmployeeName,EmployeeEmail,ApproverName,ApproverEmail,Receipt")] Contoso.Expense.Entities.Models.Expense expense) { if (ModelState.IsValid) { db.Entry(expense).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(expense)); }
// GET: Expenses/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Contoso.Expense.Entities.Models.Expense expense = db.Expenses.Find(id); if (expense == null) { return(HttpNotFound()); } return(View(expense)); }