/// <summary> /// If the recipient is null, then the message will be sent to all users. /// </summary> /// <param name="db"></param> /// <param name="subject"></param> /// <param name="message"></param> /// <param name="recipient"></param> /// <param name="sendDate"></param> /// <param name="sender"></param> static public void NewMessage(CSSDataContext db, string subject, string message, string recipient, DateTime sendDate, Alias sender) { Group group = null; if (recipient != null) { group = db.Groups.FirstOrDefault(g => g.Name == recipient); if (group == null) { throw new Exception("Could not find associated group."); } } var msg = new GroupMessage() { Subject = subject, Message = message, Group = group, DateCreated = DateTime.Now, DateExpires = DateTime.Now.AddYears(1), //Leaving at one year until discussion DateToSend = sendDate, SenderAliasId = sender.Id }; if (recipient != null) { var aliases = db.Group_Alias_GroupRoles .Where(g => g.GroupId == group.Id); foreach (var alias in aliases) { msg.GroupMessage_Alias.Add(new GroupMessage_Alias() { AliasId = alias.AliasId, DateViewed = null }); } } db.GroupMessages.InsertOnSubmit(msg); db.SubmitChanges(); }
protected void btnSaveMessage_Click(object sender, EventArgs e) { int globalMessageID; DataAccess.GroupMessage message; DateTime sendDate = DateTime.Parse(txtSendDate.Text); DateTime expirationDate = DateTime.Parse(txtExpirationDate.Text); using(CSSDataContext db = new CSSDataContext()) { if (Int32.TryParse(txtGlobalMessageID.Value, out globalMessageID) == false) { IPrincipal principal = HttpContext.Current.User; message = new GroupMessage() { Alias = Alias.GetAliasByCallsign(db, principal.Identity.Name) }; db.GroupMessages.InsertOnSubmit(message); } else { message = db.GroupMessages.FirstOrDefault(p => p.Id == globalMessageID); if (message == null) throw new Exception("Couldn't get group message for id: " + globalMessageID); } message.DateExpires = expirationDate; message.DateToSend = sendDate; message.Message = txtMessage.Text; message.Subject = txtSubject.Text; message.DateCreated = DateTime.Now; db.SubmitChanges(); } BindData(); }
private void detach_GroupMessages(GroupMessage entity) { this.SendPropertyChanging(); entity.Group = null; }
private void attach_GroupMessages(GroupMessage entity) { this.SendPropertyChanging(); entity.Group = this; }
partial void DeleteGroupMessage(GroupMessage instance);
partial void UpdateGroupMessage(GroupMessage instance);
partial void InsertGroupMessage(GroupMessage instance);
/// <summary> /// If the recipient is null, then the message will be sent to all users. /// </summary> /// <param name="db"></param> /// <param name="subject"></param> /// <param name="message"></param> /// <param name="recipient"></param> /// <param name="sendDate"></param> /// <param name="sender"></param> public static void NewMessage(CSSDataContext db, string subject, string message, string recipient, DateTime sendDate, Alias sender) { Group group = null; if (recipient != null) { group = db.Groups.FirstOrDefault(g => g.Name == recipient); if (group == null) throw new Exception("Could not find associated group."); } var msg = new GroupMessage() { Subject = subject, Message = message, Group = group, DateCreated = DateTime.Now, DateExpires = DateTime.Now.AddYears(1), //Leaving at one year until discussion DateToSend = sendDate, SenderAliasId = sender.Id }; if (recipient != null) { var aliases = db.Group_Alias_GroupRoles .Where(g => g.GroupId == group.Id); foreach (var alias in aliases) { msg.GroupMessage_Alias.Add(new GroupMessage_Alias() { AliasId = alias.AliasId, DateViewed = null }); } } db.GroupMessages.InsertOnSubmit(msg); db.SubmitChanges(); }