protected override void Save(ManagedSecurityContext sec) { bool fNew = (mInstance.Id == 0); if (mInstance.Id == 0) { mInstance.Sent = DateTime.UtcNow; } base.Save(sec); Session.Flush(); if (fNew) { ManagedAccount recepient = new ManagedAccount(Session, mInstance.RecepientAccountId); ManagedSiteConnector.TrySendAccountEmailMessageUriAsAdmin( Session, recepient, string.Format("EmailAccountMessage.aspx?id={0}", mInstance.Id)); // save a copy in Sent items AccountMessage copy = new AccountMessage(); copy.Account = Session.Load <Account>(mInstance.SenderAccountId); copy.AccountMessageFolder = ManagedAccountMessageFolder.FindRootFolder(Session, mInstance.SenderAccountId, "sent"); copy.Body = mInstance.Body; copy.RecepientAccountId = mInstance.RecepientAccountId; copy.SenderAccountId = mInstance.SenderAccountId; copy.Sent = mInstance.Sent; copy.Subject = mInstance.Subject; copy.Unread = true; Session.Save(copy); } }
public override AccountMessage GetInstance(ISession session, ManagedSecurityContext sec) { AccountMessage instance = base.GetInstance(session, sec); if (Id == 0) { // sent messages cannot be modified instance.Subject = this.Subject; instance.Body = this.Body; instance.Sent = this.Sent; instance.SenderAccountId = GetOwner(session, SenderAccountId, sec).Id; instance.RecepientAccountId = this.RecepientAccountId; // the oner is the recepient instance.Account = session.Load <Account>(RecepientAccountId); instance.Unread = true; } else { instance.Unread = this.UnRead; } if (AccountMessageFolderId == 0) { instance.AccountMessageFolder = ManagedAccountMessageFolder.FindRootFolder( session, instance.Account.Id, "inbox"); } else { instance.AccountMessageFolder = (AccountMessageFolder)session.Load( typeof(AccountMessageFolder), AccountMessageFolderId); } return(instance); }