/// <summary> /// 邮件管理页面(收件箱) /// </summary> /// <returns></returns> public ActionResult EmailManage() { EmployeeInfo emp = (EmployeeInfo)Session["Employeer"]; List <GetEmailMessages> get = dal.GetHaverEmail(emp.ID, 0, 0); ViewBag.MES = get; ViewBag.HaverName = emp.LoginName; GetNewEmail();//刷新邮件数量 // 处理"收件箱"页面的已读 //邮件id if (!string.IsNullOrEmpty(Request["id"])) { int id = Convert.ToInt32(Request["id"]); //根据id查询 GetEmailMessages g = dal.GetEmailByID(id); g.IsRead = 1; //根据id修改 bool isUpd = dal.UpdEmail(g); if (isUpd) { return(Content("1")); } } return(View()); }
/// <summary> /// 根据id将"收件箱"邮件是否被删除的状态改变 /// </summary> /// <param name="_rs"></param> /// <returns></returns> public bool UpdEmail(GetEmailMessages _em) { GetEmailMessages em = t.GetEmailMessages.Where(a => a.ID == _em.ID).FirstOrDefault(); em.IsDel = _em.IsDel; return(t.SaveChanges() > 0); }
public void Invoke_ValidData_ReturnsCorrectModel() { // prepare var findByResult = new List <EmailMessage> { new EmailMessage(), new EmailMessage(), new EmailMessage() }; var mockedEmailRepository = new Mock <IEmailRepository>(); mockedEmailRepository.Setup(r => r.FindBy(It.IsAny <Expression <Func <EmailMessage, bool> > >())) .Returns(findByResult.AsQueryable); var action = new GetEmailMessages(mockedEmailRepository.Object); // action var list = action.Invoke(2); // assert Assert.NotNull(list); Assert.Equal(2, list.Count); mockedEmailRepository.Verify(r => r.FindBy(It.IsAny <Expression <Func <EmailMessage, bool> > >()), Times.Once); }
public void Invoke_ValidData_EmptyRepository() { // prepare var mockedEmailRepository = new Mock <IEmailRepository>(); var action = new GetEmailMessages(mockedEmailRepository.Object); // action var list = action.Invoke(2); // assert Assert.Empty(list); mockedEmailRepository.Verify(r => r.FindBy(It.IsAny <Expression <Func <EmailMessage, bool> > >()), Times.Once); }
/// <summary> /// 处理"收件箱"页面的已读 /// </summary> /// <returns></returns> public ActionResult ExeDelReadedEmail() { int id = Convert.ToInt32(Request["id"]); //根据id查询 GetEmailMessages g = dal.GetEmailByID(id); g.IsDel = 1; //根据id修改 bool isUpd = dal.UpdEmail(g); if (isUpd) { return(RedirectToAction("ReadEmail")); } return(RedirectToAction("ReadEmail")); }
/// <summary> /// 处理"草稿箱"页面的发送 /// </summary> /// <returns></returns> public ActionResult DealWritedAdd() { string id = Request["id"]; string SenderID = Request["SenderID"]; string HaverID = Request["HaverID"]; string Title = Request["Title"]; string Content = Request["Content"];//.Trim(); string SendTime = Request["SendTime"]; if (SenderID != null && SenderID != "") { SendEmailMessages s = new SendEmailMessages(); s.SenderID = Convert.ToInt32(SenderID); s.HaverID = Convert.ToInt32(HaverID); s.Title = Title; s.Content = Content; s.SendTime = SendTime; s.IsSend = 1; s.IsRead = 0; s.IsDel = 0; bool isadd1 = dal.AddSendEmail(s); GetEmailMessages g = new GetEmailMessages(); g.SenderID = Convert.ToInt32(SenderID); g.HaverID = Convert.ToInt32(HaverID); g.Title = Title; g.Content = Content; g.SendTime = SendTime; g.IsRead = 0; g.IsDel = 0; bool isadd2 = dal.AddGetEmail(g); if (isadd1 && isadd2) { //发送成功后就删除在草稿箱的记录 bool isDel = dal.DelSendEmailByID(Convert.ToInt32(id)); if (isDel) { return(RedirectToAction("WritedEmail")); } } } return(RedirectToAction("WritedEmail")); }
/// <summary> /// 添加邮件(Get) /// </summary> /// <returns></returns> public bool AddGetEmail(GetEmailMessages _email) { t.GetEmailMessages.Add(_email); return(t.SaveChanges() > 0); }
/// <summary> /// 处理添加邮件 /// </summary> /// <returns></returns> public ActionResult DealAdd() { //获取登录用户的id EmployeeInfo emp = (EmployeeInfo)Session["Employeer"]; //接收前台的数据 int HaverID = Convert.ToInt32(Request["HaverID"]); string Title = Request["Title"]; string Content = Request["Content"]; DateTime dt = DateTime.Now; string SendTime = dt.ToString(); //获取保存位置 string way = Request["way"]; //群发(发送) if (way == "sendmany") { //接收员工IDS string ids = Request["ids"]; if (ids != null) { List <string> list = ids.Split(',').ToList(); for (int i = 0; i < list.Count() - 1; i++) { //添加邮件 SendEmailMessages s = new SendEmailMessages(); s.SenderID = emp.ID; s.HaverID = Convert.ToInt32(list[i]); s.Title = Title; s.Content = Content; s.SendTime = SendTime; s.IsSend = 1; s.IsRead = 0; s.IsDel = 0; bool isadd1 = dal.AddSendEmail(s); GetEmailMessages g = new GetEmailMessages(); g.SenderID = emp.ID; g.HaverID = Convert.ToInt32(list[i]); g.Title = Title; g.Content = Content; g.SendTime = SendTime; g.IsRead = 0; g.IsDel = 0; bool isadd2 = dal.AddGetEmail(g); } } } //发送 if (way == "send") { SendEmailMessages s = new SendEmailMessages(); s.SenderID = emp.ID; s.HaverID = HaverID; s.Title = Title; s.Content = Content; s.SendTime = SendTime; s.IsSend = 1; s.IsRead = 0; s.IsDel = 0; bool isadd1 = dal.AddSendEmail(s); GetEmailMessages g = new GetEmailMessages(); g.SenderID = emp.ID; g.HaverID = HaverID; g.Title = Title; g.Content = Content; g.SendTime = SendTime; g.IsRead = 0; g.IsDel = 0; bool isadd2 = dal.AddGetEmail(g); if (isadd1 && isadd2) { return(RedirectToAction("SendEmail")); } } //保存 if (way == "addsend") { SendEmailMessages s = new SendEmailMessages(); s.SenderID = emp.ID; s.HaverID = HaverID; s.Title = Title; s.Content = Content; s.SendTime = SendTime; s.IsSend = 0; s.IsRead = 0; s.IsDel = 0; bool isadd3 = dal.AddSendEmail(s); if (isadd3) { return(RedirectToAction("SendEmail")); } } return(RedirectToAction("SendEmail")); }