using System; using System.Collections.Generic; using System.Linq; using WX.CRM.BLL.Base; using WX.CRM.BLL.Res; using WX.CRM.BLL.Util; using WX.CRM.Common; using WX.CRM.DAL.Base; using WX.CRM.IBLL.Csvr; using WX.CRM.IBLL.Res; using WX.CRM.Model.Entity; namespace WX.CRM.BLL.Csvr { public class CSVR_BLACKNUMBER_BL : ICSVR_BLACKNUMBER, ICSVR_BLACKNUMBER_Q { private string clientid = Utility.GetSettingByKey("CRMClientKey"); private CACHE_BL CACHE_BL = new CACHE_BL(); public RES_MOBILEQUERYLOG_BL res_MobileQueryLog_BL = new RES_MOBILEQUERYLOG_BL(); public string CLIENTID { get { return clientid; } } private WX.CRM.IBLL.Util.ISecurityHelper sHelper = new SecurityHelper(); public CSVR_BLACKNUMBER GetEntity(decimal pkid) { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { return db.CSVR_BLACKNUMBER.FirstOrDefault(obj => obj.PKID == pkid); } } #region 添加 public bool Create(ref ValidationErrors errors, WX.CRM.Model.Entity.CSVR_BLACKNUMBER model) { try { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { model.PKID = new SEQUENCES_BL().Seq_base_get(); model.CTIME = DateTime.Now; db.CSVR_BLACKNUMBER.Add(model); return db.SaveChanges().GetResult(); } } catch (Exception ex) { errors.Add(ex.Message); return false; } } #endregion 添加 #region 删除 public bool Delete(ref ValidationErrors errors, decimal id) { try { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { WX.CRM.Model.Entity.CSVR_BLACKNUMBER entry = db.CSVR_BLACKNUMBER.FirstOrDefault(m => m.PKID == id); if (entry == null) { errors.Add("数据已经被删除!"); return false; } db.CSVR_BLACKNUMBER.Remove(entry); return db.SaveChanges().GetResult(); } } catch (Exception ex) { errors.Add(ex.Message); return false; } } #endregion 删除 public List GetAll() { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { return db.CSVR_BLACKNUMBER.ToList(); } } public WX.CRM.Model.Entity.CSVR_BLACKNUMBER GetById(decimal id) { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { return db.CSVR_BLACKNUMBER.FirstOrDefault(p => p.PKID == id); } } public List GetByResIds(string[] resId, string blackType) { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { return db.CSVR_BLACKNUMBER.Where(m => m.BLACKTYPE == blackType).Where(p => resId.Contains(p.RESID)).ToList(); } } public List GetByResUmid(string[] umids, string blackType) { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { return db.CSVR_BLACKNUMBER.Where(m => m.BLACKTYPE == blackType).Where(p => umids.Contains(p.UMID)).ToList(); } } public List GetPagingData(ref Pager pager, string resId) { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { var list = db.CSVR_BLACKNUMBER.AsQueryable(); if (!string.IsNullOrWhiteSpace(resId)) { list = list.Where(p => p.UMID.Trim() == resId); } list = list.OrderByDescending(p => p.CTIME); PagerUtil.SetPager(ref list, ref pager); return list.ToList(); } } public bool CreateEntities(ref ValidationErrors errors, List entities) { try { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { foreach (var entity in entities) { entity.PKID = new SEQUENCES_BL().Seq_base_get(); db.CSVR_BLACKNUMBER.Add(entity); } bool result = db.SaveChanges().GetResult(); ; return result; } } catch (Exception ex) { errors.Add(ex.Message); return false; } } /// /// 查询黑名单 /// /// /// public List GetBlackNumberByRESID(string resid, decimal userId, out string mobile) { mobile = ""; try { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { RES_RESOURCEMOBILE_BL bl = new RES_RESOURCEMOBILE_BL(); PhoneLogModel phoneLogModel = new PhoneLogModel { Method = System.Reflection.MethodBase.GetCurrentMethod().Name, userid = userId }; mobile = bl.GetNumberByResId(resid, phoneLogModel); resid = resid.Trim(); var q = db.CSVR_BLACKNUMBER.Where(p => p.RESID == resid); return q.ToList(); } } catch (Exception ex) { LogHelper.Error(ex); return null; } } } }