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 = "CategoryId,Amount,Title,Description")] TransactionVM transactionVM)
        {
            if (ModelState.IsValid)
            {
                Transaction transaction = new Transaction();
                transaction.Amount = Decimal.Parse(transactionVM.Amount, NumberStyles.Currency);
                transaction.CreatedOn = DateTime.Now;
                transaction.Description = transactionVM.Description;
                transaction.Title = transactionVM.Title;
                transaction.CategoryId = transactionVM.CategoryId;

                db.Transactions.Add(transaction);
                db.SaveChanges();

                // Checking to see if an email must be sent off
                var categoryInformation = db.Categories
                    .Where(c => c.Id == transaction.CategoryId)
                     .Select(a => new
                     {
                         Amount = a.Transactions.Select(t => t.Amount).Sum(),
                         Limit = a.Limit,
                     }).FirstOrDefault();

                if (categoryInformation.Amount > categoryInformation.Limit)
                {
                    List<string> users = new List<string>();
                    Category category = db.Categories.Find(transaction.CategoryId);
                    users.AddRange(db.Budgets.Find(category.Budget.Id).Users.Select(user => user.UserName).ToList());
                    HomeController.EmailNotification(users, transaction, category);
                }

                return RedirectToAction("Details", "Categories", new { id = transaction.CategoryId });
            }

            return View(transactionVM);
        }