TG.WXCRM.V4/BLL/Csvr/CSVR_BLACKNUMBER_BL.cs

177 lines
6.2 KiB
C#

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<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> 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<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.UMID.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, 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;
}
}
}
}