public ActionResult AddContact(Tnsmtp_ContactMap model) { if (model.Gid == 0) { return(FailResult("请先添加小组!")); } DataAccess.Tnsmtp_Contact tnsmtp = new DataAccess.Tnsmtp_Contact(); if (tnsmtp.SelectIsExtByEmail(SysUser.UserId, model.Email, model.Gid.Value)) { return(FailResult("该联系人已存在!")); } DataAccess.Tnsmtp_ContactCollection tnsmtp_ContactCollection = new DataAccess.Tnsmtp_ContactCollection(); tnsmtp_ContactCollection.ListCount(SysUser.UserId, model.Gid.Value); if (tnsmtp_ContactCollection.DataTable.Rows.Count > 2000) { return(FailResult("该小组已超过2000条邮箱!")); } DataAccess.Tnsmtp_Contact tnsmtp_Contact = new DataAccess.Tnsmtp_Contact(); tnsmtp_Contact.ContactName = model.ContactName; tnsmtp_Contact.Email = model.Email; tnsmtp_Contact.Gid = model.Gid; tnsmtp_Contact.Status = 0; tnsmtp_Contact.UserId = SysUser.UserId; if (!tnsmtp_Contact.Insert()) { return(FailResult("添加失败!")); } return(SuccessResult("添加成功!")); }
/// <summary> /// 添加联系人表数据 /// </summary> /// <returns></returns> private bool AddContactTable(Tnsmtp_EmailMap model) { DataAccess.Tnsmtp_Contact tnsmtp_Contact = new DataAccess.Tnsmtp_Contact(); tnsmtp_Contact.ReferenceTransactionFrom(this.Transaction); if (tnsmtp_Contact.SelectByEmail(model.Userid, model.Inmail)) { model.RecId = tnsmtp_Contact.ContactId; } if (!model.RecId.HasValue) { #region 如果用户没有 "常用联系人" 这个组则添加这个组 DataAccess.Tnsmtp_Contactgroup tnsmtp_Contactgroup = new DataAccess.Tnsmtp_Contactgroup(); tnsmtp_Contactgroup.ReferenceTransactionFrom(this.Transaction); if (!tnsmtp_Contactgroup.SelectByGroupName(model.Userid, "常用联系人")) { tnsmtp_Contactgroup.Groupname = "常用联系人"; tnsmtp_Contactgroup.Userid = model.Userid; tnsmtp_Contactgroup.Status = 0; if (!tnsmtp_Contactgroup.Insert()) { Alert("添加常用联系人分组失败"); return(false); } } #endregion #region 添加联系人 tnsmtp_Contact.ContactName = model.Inmail; tnsmtp_Contact.Email = model.Inmail; tnsmtp_Contact.Gid = tnsmtp_Contactgroup.Gid; tnsmtp_Contact.Status = 0; tnsmtp_Contact.UserId = model.Userid; tnsmtp_Contact.CateId = 1; if (!tnsmtp_Contact.Insert()) { Alert("添加常用联系人失败"); return(false); } #endregion } return(true); }
public bool Enter(List <int> spids, int gid, int userid) { Tnsmtp_SpidermailCollection collection = new Tnsmtp_SpidermailCollection(); if (!collection.ListBySpids(spids)) { Alert("查询失败!"); return(false); } DataAccess.Tnsmtp_ContactCollection tnsmtp_ContactCollection = new DataAccess.Tnsmtp_ContactCollection(); tnsmtp_ContactCollection.ListCount(userid, gid); if (tnsmtp_ContactCollection.DataTable.Rows.Count > 2000) { Alert("该小组已超过2000条邮箱!"); return(false); } BeginTransaction(); for (int i = 0; i < collection.DataTable.Rows.Count; i++) { string email = collection.DataTable.Rows[i][Tnsmtp_Spidermail._EMAIL].ToString(); Tnsmtp_Contact tnsmtp = new DataAccess.Tnsmtp_Contact(); if (tnsmtp.SelectIsExtByEmail(userid, email, gid)) { continue; } DataAccess.Tnsmtp_Contact tnsmtp_Contact = new DataAccess.Tnsmtp_Contact(); tnsmtp_Contact.ReferenceTransactionFrom(this.Transaction); tnsmtp_Contact.ContactName = collection.DataTable.Rows[i][Tnsmtp_Spidermail._FIRSTNAME].ToString(); tnsmtp_Contact.Email = email; tnsmtp_Contact.Gid = gid; tnsmtp_Contact.Status = 0; tnsmtp_Contact.UserId = userid; if (!tnsmtp_Contact.Insert()) { Rollback(); Alert("添加失败!"); return(false); } } Commit(); return(true); }
public bool Import(DataTable dt, int userid) { if (dt.Rows.Count <= 0) { Alert("没有数据!"); return(false); } RemoveEmpty(dt); BeginTransaction(); for (int i = 0; i < dt.Rows.Count; i++) { DataAccess.Tnsmtp_Contact tnsmtp_Contact = new DataAccess.Tnsmtp_Contact(); tnsmtp_Contact.ReferenceTransactionFrom(this.Transaction); tnsmtp_Contact.ContactName = dt.Rows[i]["name"].ToString(); tnsmtp_Contact.Email = dt.Rows[i]["email"].ToString(); int gid = 0; int.TryParse(dt.Rows[i]["gid"].ToString(), out gid); DataAccess.Tnsmtp_Contactgroup tnsmtp_Contactgroup = new DataAccess.Tnsmtp_Contactgroup(); if (!tnsmtp_Contactgroup.SelectByPK(gid)) { Rollback(); Alert("联系人小组ID不正确小组ID:" + gid); return(false); } tnsmtp_Contact.Gid = gid; tnsmtp_Contact.Status = 0; tnsmtp_Contact.UserId = userid; if (!tnsmtp_Contact.Insert()) { Rollback(); Alert("插入数据失败:" + tnsmtp_Contact.ContactName); return(false); } } Commit(); return(true); }