protected void btnSaveUser_Click(object sender, EventArgs e) { string userName = this.txtUserName.Text.Trim(); string groupId = this.ddlGroupID.SelectedValue; string subGroupId = this.ddlSubGroupID.SelectedValue; string email = this.txtEmail.Text.Trim(); string phone = this.txtPhone.Text.Trim(); string summary = this.txtSummary.Text.Trim(); using (var context = new EmailContext()) { if (this.hideUserAction.Value == "add") { var entity = new EmailUser { UserName = userName, GroupID = int.Parse(groupId), SubGroupID = int.Parse(subGroupId), Email = email, Phone = phone, Summary = summary, AddDate = DateTime.Now }; context.EmailUsers.Add(entity); context.SaveChanges(); this.txtUserName.Text = string.Empty; this.txtEmail.Text = string.Empty; this.txtPhone.Text = string.Empty; this.txtSummary.Text = string.Empty; } if (this.hideUserAction.Value == "edit") { var id = this.hideUserID.Value; var entity = context.EmailUsers.Find(int.Parse(id)); if (entity != null) { entity.UserName = userName; entity.GroupID = int.Parse(groupId); entity.SubGroupID = int.Parse(subGroupId); entity.Email = email; entity.Phone = phone; entity.Summary = summary; entity.AddDate = DateTime.Now; context.SaveChanges(); this.txtUserName.Text = string.Empty; this.txtEmail.Text = string.Empty; this.txtPhone.Text = string.Empty; this.txtSummary.Text = string.Empty; this.hideUserAction.Value = "add"; this.hideUserID.Value = "0"; } } InitRepeater5(this.AspNetPager5.CurrentPageIndex, int.Parse(this.ddlGroupID.SelectedValue), int.Parse(this.ddlSubGroupID.SelectedValue)); } }
protected void btnSaveGroup_Click(object sender, EventArgs e) { string groupName = this.txtGroupName.Text.Trim(); string parentId = this.ddlParentGroupID.SelectedValue; string groupDescription = this.txtGroupDescription.Text.Trim(); using (var context = new EmailContext()) { if (this.hideGroupAction.Value == "add") { var entity = context.EmailGroups.FirstOrDefault(g => g.GroupName == groupName); if (entity == null) { entity = new EmailGroup { GroupName = groupName, ParentID = int.Parse(parentId), GroupDescription = groupDescription }; context.EmailGroups.Add(entity); context.SaveChanges(); this.txtGroupName.Text = string.Empty; this.txtGroupDescription.Text = string.Empty; } else { ScriptManager.RegisterStartupScript(this.GroupUpdatePanel, GetType(), "a", "alert('此分组名称已经存在')", true); return; } } if (this.hideGroupAction.Value == "edit") { var id = this.hideGroupID.Value; var entity = context.EmailGroups.Find(int.Parse(id)); if (entity != null) { entity.GroupName = groupName; entity.ParentID = int.Parse(parentId); entity.GroupDescription = groupDescription; } context.SaveChanges(); this.txtGroupName.Text = string.Empty; this.ddlParentGroupID.SelectedIndex = -1; this.txtGroupDescription.Text = string.Empty; this.hideGroupID.Value = "0"; this.hideGroupAction.Value = "add"; } } InitRepeater4(this.AspNetPager4.CurrentPageIndex); ddlParentGroupID_GetData(); }
public async Task Get_GetsExistingEmail() { // arrange using var contextFactory = new TestEmailContextFactory(); using EmailContext context = contextFactory.CreateContext(); // insert test data here, or maybe have a helper method somewhere to possibly share it between tests var insertedEmail = new Message { Guid = Guid.NewGuid(), OrigDate = new DateTimeOffset(2021, 1, 1, 0, 0, 0, new TimeSpan(0)), From = new Account { Address = "*****@*****.**" }, Subject = "example subject", Body = "asdf" }; context.Messages.Add(insertedEmail); context.SaveChanges(); var repo = new MessageRepository(context); // act Business.Email email = await repo.GetByIdAsync(insertedEmail.Guid); // assert Assert.Equal(insertedEmail.Guid, email.Id); Assert.Equal(insertedEmail.Body, email.Body); Assert.Equal(insertedEmail.OrigDate, email.OrigDate); Assert.Equal(insertedEmail.From.Address, email.From); Assert.Equal(insertedEmail.Subject, email.Subject); }
public static void EnsurePopulated(IApplicationBuilder app) { EmailContext context = app.ApplicationServices .CreateScope().ServiceProvider.GetRequiredService <EmailContext>(); if (context.Database.GetPendingMigrations().Any()) { context.Database.Migrate(); } if (!context.Emails.Any()) { context.Emails.AddRange( new Email { E_mailDirtetion = "*****@*****.**", Pasword = "ljagn", Id_user = 1, Id_permissions = 100 }, new Email { E_mailDirtetion = "*****@*****.**", Pasword = "ojr ngea", Id_user = 2, Id_permissions = 110 }, new Email { E_mailDirtetion = "*****@*****.**", Pasword = "lsotkrhnow", Id_user = 3, Id_permissions = 111 }, new Email { E_mailDirtetion = "*****@*****.**", Pasword = "lsotk6u0rhnow", Id_user = 4, Id_permissions = 001 }, new Email { E_mailDirtetion = "*****@*****.**", Pasword = "wjsrtyu.ry", Id_user = 5, Id_permissions = 101 } ); context.SaveChanges(); } }
protected void btnSendEmail_Click(object sender, EventArgs e) { string receiver = this.txtReceiver.Text.Trim(); string subject = this.txtSubject.Text.Trim(); MailMessage mailMessage = new MailMessage(); string content = this.hideMailContent.Value; mailMessage.From = "*****@*****.**"; mailMessage.Subject = subject; mailMessage.IsBodyHtml = true; mailMessage.HtmlBody = content; string[] users = receiver.Split(','); foreach (string user in users) { int startIndex = user.IndexOf('<') + 1; int length = user.Length; string email = user.Substring(startIndex, length - startIndex - 1); mailMessage.To.Add(email); } //创建附件 if (Session["tempTable"] != null) { DataTable table = (DataTable)Session["tempTable"]; foreach (DataRow row in table.Rows) { mailMessage.Attachments.Add(new Attachment(row["FilePath"].ToString())); } } SmtpClient client = AsposeUtilities.GetSmtpClient(this.Request.ApplicationPath); try { client.Send(mailMessage); using (var context = new EmailContext()) { var entity = new SendLog { Sender = CookieUtilities.GetCookieValue("username"), Receiver = receiver, SendTime = DateTime.Now, SendType = "Email" }; context.SendLogs.Add(entity); context.SaveChanges(); } ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('邮件发送成功')", true); } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('邮件发送失败!" + ex.Message + "')", true); } }
private void GetFirstEmails() { Outlook.MAPIFolder inbox = this._application.ActiveExplorer().Session.GetDefaultFolder (Outlook.OlDefaultFolders.olFolderInbox); Outlook.Items unreadItems = inbox.Items.Restrict("[Unread]=true"); MessageBox.Show( string.Format("Unread items in Inbox = {0}", unreadItems.Count)); if (unreadItems.Count == 0) { return; } foreach (object Item in unreadItems) { Items_ItemAdd(Item); } _ctx.SaveChanges(); // There's a weird bug which causes some emails to initially not save or reload as null, so this // function has to be recalled until all the emails are loaded. GetFirstEmails(); }
public static void PopulateTestData(EmailContext dbContext) { dbContext.EmailList.Add(new ForgotPass { Email = "*****@*****.**" }); dbContext.EmailList.Add(new ForgotPass { Email = "*****@*****.**" }); dbContext.SaveChanges(); }
protected void lnkUserDelete_Command(object sender, CommandEventArgs e) { var id = e.CommandArgument.ToString(); using (var context = new EmailContext()) { var entity = context.EmailUsers.Find(int.Parse(id)); if (entity != null) { context.EmailUsers.Remove(entity); context.SaveChanges(); InitRepeater5(this.AspNetPager5.CurrentPageIndex, int.Parse(this.ddlGroupID.SelectedValue), int.Parse(this.ddlSubGroupID.SelectedValue)); } } }
protected void btnSendWeiXin_Click(object sender, EventArgs e) { string content = this.txtWeiXinContent.Text; try { int count = 0; foreach (RepeaterItem item in this.Repeater3.Items) { HtmlInputCheckBox checkBox = (HtmlInputCheckBox)item.FindControl("inlineCheckbox1"); if (checkBox.Checked) { count++; } } if (count == 0) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('请选择接收用户')", true); return; } StringBuilder receiverBuilder = new StringBuilder(); foreach (RepeaterItem item in this.Repeater3.Items) { HtmlInputCheckBox checkBox = (HtmlInputCheckBox)item.FindControl("inlineCheckbox1"); } string receiver = receiverBuilder.ToString().TrimEnd(','); using (var context = new EmailContext()) { var entity = new SendLog { Sender = CookieUtilities.GetCookieValue("username"), Receiver = receiver, SendTime = DateTime.Now, SendType = "WeiXin" }; context.SendLogs.Add(entity); context.SaveChanges(); } ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('微信发送成功')", true); } catch (Exception) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('微信发送可能,可能部分用户我发收到微信内容!')", true); } }
protected void lnkGroupDelete_Command(object sender, CommandEventArgs e) { var groupId = e.CommandArgument.ToString(); using (var context = new EmailContext()) { var entity = context.EmailGroups.Find(int.Parse(groupId)); if (entity != null) { int parentId = int.Parse(groupId); context.EmailGroups.Remove(entity); var entities = context.EmailGroups.Where(g => g.ParentID == parentId); context.EmailGroups.RemoveRange(entities); context.SaveChanges(); this.txtGroupName.Text = string.Empty; this.ddlParentGroupID.SelectedIndex = -1; this.txtGroupDescription.Text = string.Empty; this.hideGroupID.Value = "0"; this.hideGroupAction.Value = "add"; InitRepeater4(this.AspNetPager4.CurrentPageIndex); ddlParentGroupID_GetData(); } } }
public void AddEmail([FromBody] Email toAdd) { _context.Emails.Add(toAdd); _context.SaveChanges(); }
public void Save() { _emailContext.SaveChanges(); }
public void Save() { _context.SaveChanges(); }