/// <summary> /// Audits Changes to a Specific Entity /// </summary> /// <typeparam name="T">The Data Entity Type</typeparam> /// <param name="dataContext">The Data Context</param> /// <param name="modifiedEntity">The Entity To Audit</param> /// <param name="target"></param> /// <param name="userid"></param> public static void LogChanges <T>(ioschoolsDBDataContext dataContext, T modifiedEntity, string target, long userid) where T : class { if (dataContext == null || modifiedEntity == null) { return; } var sb = new StringBuilder(); sb.AppendFormat("{0}: ", target); foreach (ModifiedMemberInfo modifiedProperty in dataContext.GetTable <T>().GetModifiedMembers(modifiedEntity)) { //log changes // field[original:new] field[original:new] sb.AppendFormat("{0}[{1} -> {2}] ", modifiedProperty.Member.Name, modifiedProperty.OriginalValue, modifiedProperty.CurrentValue); } var change = new changelog { changes = sb.ToString(), created = DateTime.Now, userid = userid }; dataContext.changelogs.InsertOnSubmit(change); dataContext.SubmitChanges(); }
public baseController() { baseviewmodel = new BaseViewModel(); db = new ioschoolsDBDataContext(); repository = new Repository(db); auth = new UserAuth(); }
private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e) { // get the identifier var token = (mail)e.UserState; if (e.Error != null) { if (e.Error.GetType() != typeof(SmtpFailedRecipientException)) { // reinsert back into database using (var db = new ioschoolsDBDataContext()) { db.mails.InsertOnSubmit(token); db.SubmitChanges(); } } } // update order status //ITradelrRepository repository = new TradelrRepository(); //repository.UpdateOrderStatus(token.orderID, token.userID, OrderStatus.SENT); }
public static void SetStudentInactiveIfLeavingDateSet() { var date = DateTime.Now; var myLock = new object(); lock (myLock) { using (var db = new ioschoolsDBDataContext()) { bool hasChange = false; // check for expired students var groups = db.registrations.GroupBy(x => x.user); foreach (var g in groups) { var activeRow = g.Where(x => x.admissionDate.HasValue) .OrderBy(x => x.admissionDate).LastOrDefault(); if (activeRow != null) { var currentStatus = (UserSettings)activeRow.user.settings; if (activeRow.leftDate.HasValue) { if (date > activeRow.leftDate.Value && !currentStatus.HasFlag(UserSettings.INACTIVE)) { activeRow.user.settings = activeRow.user.SetFlag(UserSettings.INACTIVE); hasChange = true; } } else { if (date > activeRow.admissionDate.Value && currentStatus.HasFlag(UserSettings.INACTIVE)) { activeRow.user.settings = activeRow.user.UnsetFlag(UserSettings.INACTIVE); hasChange = true; } } } } // check for expired staff var staffgroups = db.employments.GroupBy(x => x.user); foreach (var g in staffgroups) { var activeRow = g.Where(x => x.start_date.HasValue) .OrderBy(x => x.start_date).LastOrDefault(); if (activeRow != null) { var currentStatus = (UserSettings)activeRow.user.settings; if (activeRow.end_date.HasValue) { if (date > activeRow.end_date.Value && !currentStatus.HasFlag(UserSettings.INACTIVE)) { activeRow.user.settings = activeRow.user.SetFlag(UserSettings.INACTIVE); hasChange = true; } } else { if (date > activeRow.start_date.Value && currentStatus.HasFlag(UserSettings.INACTIVE)) { activeRow.user.settings = activeRow.user.UnsetFlag(UserSettings.INACTIVE); hasChange = true; } } } } if (hasChange) { try { db.SubmitChanges(); } catch (Exception ex) { Syslog.Write(ex); } } } } }
/// <summary> /// /// </summary> /// <param name="entry"></param> /// <param name="isAsync"></param> /// <param name="queueMail"></param> /// <param name="ccList"></param> public static void SendMail(mail entry, bool isAsync, bool queueMail, IEnumerable <string> ccList = null) { // need to check for invalid email address if (!entry.toEmail.IsEmail()) { return; } if (queueMail) { // queue it instead using (var db = new ioschoolsDBDataContext()) { db.mails.InsertOnSubmit(entry); db.SubmitChanges(); } return; } var from = new MailAddress(MAIL_SOURCE_ADDRESS, " School", Encoding.UTF8); MailAddress replyto = null; if (!string.IsNullOrEmpty(entry.fromEmail)) { replyto = new MailAddress(entry.fromEmail, entry.fromName, Encoding.UTF8); } var to = new MailAddress(entry.toEmail, entry.toName, Encoding.UTF8); var msg = new MailMessage(from, to) { Body = entry.body, IsBodyHtml = true, BodyEncoding = Encoding.UTF8, Subject = entry.subject, SubjectEncoding = Encoding.UTF8 }; // add footer if (replyto != null) { msg.ReplyTo = replyto; msg.Body += "<p>You can directly reply to this email.</p>"; } else { msg.Body += "<p>This is an automated mail. Please DO NOT reply to this email.</p>"; } // cclist if (ccList != null) { foreach (var email in ccList) { msg.CC.Add(new MailAddress(email)); } } var smtp = new SmtpClient(MAIL_SERVER) { Credentials = new NetworkCredential(MAIL_SOURCE_ADDRESS, MAIL_PASSWORD) }; if (isAsync) { smtp.SendCompleted += SendCompletedCallback; smtp.SendAsync(msg, entry); } else { try { smtp.Send(msg); } catch (SmtpFailedRecipientException ex) { Syslog.Write(ex); } catch (Exception ex) { Syslog.Write(ex); // then we need to reinsert back // reinsert back into database using (var db = new ioschoolsDBDataContext()) { db.mails.InsertOnSubmit(entry); db.SubmitChanges(); } } } }
public Repository(ioschoolsDBDataContext db) { this.db = db; }
public Repository() { db = new ioschoolsDBDataContext(); }