/// <summary> /// 修改 /// </summary> /// <param name="mailInBox"></param> /// <returns></returns> public int Update(Model.MailInBox mailInBox) { using (var db = new DataContext()) { db.Update(mailInBox); return(db.SaveChanges()); } }
/// <summary> /// 还原一个已删除邮件 /// </summary> /// <param name="mailDeletedBox"></param> /// <returns></returns> public int Recovery(Model.MailDeletedBox mailDeletedBox) { using (var db = new DataContext()) { Model.MailInBox mailInBox = new Model.MailInBox(); mailInBox.ContentsId = mailDeletedBox.ContentsId; mailInBox.Id = mailDeletedBox.Id; mailInBox.IsRead = mailDeletedBox.IsRead; mailInBox.OutBoxId = mailDeletedBox.OutBoxId; mailInBox.ReadDateTime = mailDeletedBox.ReadDateTime; mailInBox.SendDateTime = mailDeletedBox.SendDateTime; mailInBox.SendUserId = mailDeletedBox.SendUserId; mailInBox.Subject = mailDeletedBox.Subject; mailInBox.SubjectColor = mailDeletedBox.SubjectColor; mailInBox.UserId = mailDeletedBox.UserId; db.Add(mailInBox); db.Remove(mailDeletedBox); return(db.SaveChanges()); } }
/// <summary> /// 删除 /// </summary> /// <param name="mailInBox"></param> /// <returns></returns> public int DeleteMailInBox(Model.MailInBox mailInBox) { return(mailInBoxData.Delete(mailInBox)); }
/// <summary> /// 修改 /// </summary> /// <param name="mailInBox"></param> /// <returns></returns> public int UpdateMailInBox(Model.MailInBox mailInBox) { return(mailInBoxData.Update(mailInBox)); }
/// <summary> /// 添加 /// </summary> /// <param name="mailInBox"></param> /// <returns></returns> public int AddMailInBox(Model.MailInBox mailInBox) { return(mailInBoxData.Add(mailInBox)); }
/// <summary> /// 发送邮件 /// </summary> /// <param name="mailOutBox"></param> /// <param name="mailContent"></param> /// <param name="receiveUsers">接收人员</param> /// <param name="carbonCopyUsers">抄送人员</param> /// <param name="secretCopyUsers">密送人员</param> /// <param name="isAdd">是否新增</param> /// <returns></returns> public int Send(Model.MailOutBox mailOutBox, Model.MailContent mailContent, List <Model.User> receiveUsers, List <Model.User> carbonCopyUsers, List <Model.User> secretCopyUsers, bool isAdd) { using (var db = new DataContext()) { int i = 0; if (isAdd) { i += db.Add(mailOutBox); } else { i += db.Update(mailOutBox); db.Remove(mailContent); } db.Add(mailContent); if (mailOutBox.Status == 1)//如果是发送,则添加收件箱数据,存草稿不添加 { List <Model.MailInBox> mailInBoxes = new List <Model.MailInBox>(); //发送 foreach (var user in receiveUsers) { Model.MailInBox mailInBox = new Model.MailInBox { ContentsId = mailContent.Id, Id = Guid.NewGuid(), IsRead = 0, SendDateTime = mailOutBox.SendDateTime, SendUserId = mailOutBox.UserId, Subject = mailOutBox.Subject, SubjectColor = mailOutBox.SubjectColor, UserId = user.Id, OutBoxId = mailOutBox.Id, MailType = 1 }; mailInBoxes.Add(mailInBox); } //抄送 foreach (var user in carbonCopyUsers) { Model.MailInBox mailInBox = new Model.MailInBox { ContentsId = mailContent.Id, Id = Guid.NewGuid(), IsRead = 0, SendDateTime = mailOutBox.SendDateTime, SendUserId = mailOutBox.UserId, Subject = mailOutBox.Subject, SubjectColor = mailOutBox.SubjectColor, UserId = user.Id, OutBoxId = mailOutBox.Id, MailType = 2 }; mailInBoxes.Add(mailInBox); } //密送 foreach (var user in secretCopyUsers) { Model.MailInBox mailInBox = new Model.MailInBox { ContentsId = mailContent.Id, Id = Guid.NewGuid(), IsRead = 0, SendDateTime = mailOutBox.SendDateTime, SendUserId = mailOutBox.UserId, Subject = mailOutBox.Subject, SubjectColor = mailOutBox.SubjectColor, UserId = user.Id, OutBoxId = mailOutBox.Id, MailType = 3 }; mailInBoxes.Add(mailInBox); } db.AddRange(mailInBoxes); } return(db.SaveChanges()); } }