158 lines
5.4 KiB
C#
158 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using WX.CRM.BLL.Base;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.DAL.Base;
|
|
using WX.CRM.IBLL.Csvr;
|
|
using WX.CRM.Model.Entity;
|
|
|
|
namespace WX.CRM.BLL.Csvr
|
|
{
|
|
public class CSVR_BLACKNUMBER_BL : ICSVR_BLACKNUMBER, ICSVR_BLACKNUMBER_Q
|
|
{
|
|
string clientid = Utility.GetSettingByKey("CRMClientKey");
|
|
|
|
public string CLIENTID { get { return clientid; } }
|
|
|
|
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<WX.CRM.Model.Entity.CSVR_BLACKNUMBER> 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<WX.CRM.Model.Entity.CSVR_BLACKNUMBER> 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<WX.CRM.Model.Entity.CSVR_BLACKNUMBER> 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.RESID.Trim() == resId);
|
|
}
|
|
list = list.OrderByDescending(p => p.CTIME);
|
|
PagerUtil.SetPager<WX.CRM.Model.Entity.CSVR_BLACKNUMBER>(ref list, ref pager);
|
|
return list.ToList();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public bool CreateEntities(ref ValidationErrors errors, List<WX.CRM.Model.Entity.CSVR_BLACKNUMBER> 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; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询黑名单
|
|
/// </summary>
|
|
/// <param name="number"></param>
|
|
/// <returns></returns>
|
|
public List<CSVR_BLACKNUMBER> GetBlackNumberByRESID(string resid, out string mobile)
|
|
{
|
|
mobile = "";
|
|
try
|
|
{
|
|
WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext();
|
|
var mobiles = new RESOURCEMOBILE_DAL().GetMobile(resid);
|
|
resid = resid.Trim();
|
|
var q = db.CSVR_BLACKNUMBER.Where(p => p.RESID == resid);
|
|
mobile = string.Join(",", mobiles.Select(o => sHelper.decyptData(clientid, o.MOBILE)));
|
|
return q.ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex);
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|