public static void EmailNotification(List<string> users, Transaction transaction, Category category) { // Create the email object first, then add the properties. var myMessage = new SendGridMessage(); // Add the message properties. myMessage.From = new MailAddress("*****@*****.**"); myMessage.AddTo(users); myMessage.Subject = String.Format("{0} is over its limit.", category.Title); myMessage.Text = String.Format("{0} has either reached, or surpassed its limit of {1:C}. It's current balance is {2:C}.\r\nMost recent transaction: {3}\r\nDescription: {4}\r\nDate: {5}\r\nAmount: {6}", category.Title, category.Limit, category.Balance, transaction.Title, transaction.Description, transaction.CreatedOn, transaction.FormatedAmount); var credentials = new NetworkCredential("*****@*****.**", "Password@123"); var transportWeb = new SendGrid.Web(credentials); transportWeb.DeliverAsync(myMessage); }
public ActionResult Create([Bind(Include = "BudgetId,Limit,Title,Description")] CategoryVM categoryVM) { if (ModelState.IsValid) { if (db.Categories.Any(b => b.Title == categoryVM.Title)) { return View(categoryVM); } Category category = new Category(); category.Description = categoryVM.Description; category.Limit = Decimal.Parse(categoryVM.Limit, NumberStyles.Currency); category.Title = categoryVM.Title; category.Budget = db.Budgets.Find(categoryVM.BudgetId); db.Categories.Add(category); db.SaveChanges(); return RedirectToAction("Details", "Budgets", new { id = category.BudgetId }); } return View(categoryVM); }