public int SendMail(tblTradeRequest req, int qty) { int s = 0; tblUser user = db.tblUsers.SingleOrDefault(x => x.uid == req.uid); string eMail = user.email; string fname = user.fname; tblTransactions trans = db.tblTransactions.OrderByDescending(x => x.time).First(); try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(eMail); mail.Subject = "Trade Requested Executed"; mail.Body = "Hello " + fname + ",\n\nCongratulations! Your Trade Request with RequestId " + req.requestId + " is successfully executed."; mail.Body += "\n\nBelow are the details of Transaction :\nTransaction Id: " + trans.transactionId + "\nStock Name: " + db.getStockName(trans.buyerReqId).FirstOrDefault().ToString() + "\nQuantity: " + qty + "\n\nPlease find more details on website.\n\n\nHappy Trading!"; SmtpServer.Port = 587; SmtpServer.UseDefaultCredentials = false; SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "%TGB6yhn^YHN5tgb"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); SmtpServer.Dispose(); } catch (Exception ex) { s = 0; } return(s); }
public void UpdateTblTransaction(int BuyerReqId, int SellerReqId, double BuyPrice, double SellPrice, int qty) { tblTransactions transaction = new tblTransactions(); transaction.buyerReqId = BuyerReqId; transaction.sellerReqId = SellerReqId; transaction.buyPrice = Convert.ToDecimal(BuyPrice); transaction.sellPrice = Convert.ToDecimal(SellPrice); transaction.quantity = qty; transaction.time = DateTime.Now; db.tblTransactions.Add(transaction); }