public static LeaveRequestDescription getLatestDescription(LeaveRequestInfo lri,LeaveManagerContext db) { var q = from l in db.LeaveRequestDescription where l.LeaveRequestInfo.LeaveRequestInfoID == lri.LeaveRequestInfoID select l; var latest = q.OrderByDescending(i=>i.CreateDate).First(); return latest; }
public static Dictionary<LeaveRequestInfo, LeaveRequestDescription> getAllLeaveRequests(LeaveManagerContext db) { Dictionary<LeaveRequestInfo, LeaveRequestDescription> leaveRequests = new Dictionary<LeaveRequestInfo, LeaveRequestDescription>(); foreach (LeaveRequestInfo lri in db.LeaveRequestInfo) { LeaveRequestDescription latestDesc = getLatestDescription(lri,db); leaveRequests.Add(lri, latestDesc); } return leaveRequests; }
public static void sendMailUsingDBSettings(LeaveManagerContext database, string to,string subject,string body) { try { MailSettings ms = new MailSettings(); ms = database.MailSettings.First(); MailMessage message = new MailMessage(); message.From = new MailAddress(ms.Username); message.To.Add(new MailAddress(to)); message.IsBodyHtml = true; message.BodyEncoding = Encoding.UTF8; message.Subject = subject; message.Body = body; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = ms.Username, Password = ms.Password }; smtp.UseDefaultCredentials = false; smtp.Credentials = credential; smtp.Host = ms.Host; smtp.Port = ms.Port; smtp.EnableSsl = true; smtp.Send(message); } } catch { } }