/// <summary> /// 保存邮件表单(发送、存入草稿、草稿编辑) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="emailContentEntity">邮件实体</param> /// <param name="addresssIds">收件人</param> /// <param name="copysendIds">抄送人</param> /// <param name="bccsendIds">密送人</param> /// <returns></returns> public void SaveForm(string keyValue, EmailContentEntity emailContentEntity, string[] addresssIds, string[] copysendIds, string[] bccsendIds) { if (emailContentEntity.F_SendState == 0) { if (!string.IsNullOrEmpty(keyValue)) { emailContentEntity.Modify(keyValue); this.BaseRepository().Update(emailContentEntity); } else { emailContentEntity.Create(); this.BaseRepository().Insert(emailContentEntity); } } else { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { if (!string.IsNullOrEmpty(keyValue)) { emailContentEntity.Modify(keyValue); db.Update(emailContentEntity); } else { emailContentEntity.Create(); db.Insert(emailContentEntity); } #region 收件人 foreach (var item in addresssIds) { EmailAddresseeEntity emailAddresseeEntity = new EmailAddresseeEntity(); emailAddresseeEntity.Create(); emailAddresseeEntity.F_ContentId = emailContentEntity.F_ContentId; emailAddresseeEntity.F_RecipientId = item; emailAddresseeEntity.F_RecipientState = 0; db.Insert(emailAddresseeEntity); } #endregion #region 抄送人 foreach (var item in copysendIds) { EmailAddresseeEntity emailAddresseeEntity = new EmailAddresseeEntity(); emailAddresseeEntity.Create(); emailAddresseeEntity.F_ContentId = emailContentEntity.F_ContentId; emailAddresseeEntity.F_RecipientId = item; emailAddresseeEntity.F_RecipientState = 1; db.Insert(emailAddresseeEntity); } #endregion #region 密送人 foreach (var item in bccsendIds) { EmailAddresseeEntity emailAddresseeEntity = new EmailAddresseeEntity(); emailAddresseeEntity.Create(); emailAddresseeEntity.F_ContentId = emailContentEntity.F_ContentId; emailAddresseeEntity.F_RecipientId = item; emailAddresseeEntity.F_RecipientState = 2; db.Insert(emailAddresseeEntity); } #endregion db.Commit(); } catch (System.Exception) { db.Rollback(); throw; } } }