104 lines
2.9 KiB
C#
104 lines
2.9 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.IBLL.Wx;
|
||
using WX.CRM.Model.Entity;
|
||
|
||
namespace WX.CRM.BLL.Wx
|
||
{
|
||
public class WX_USERIMEI_BL : DbContextRepository<WX_USERIMEI>, IWX_USERIMEI
|
||
{
|
||
public bool BatchInsert(string imeis)
|
||
{
|
||
try
|
||
{
|
||
if (string.IsNullOrWhiteSpace(imeis))
|
||
return false;
|
||
imeis = imeis.Trim();
|
||
string[] iemiArr = imeis.Split(',');
|
||
foreach (var imei in iemiArr)
|
||
{
|
||
if (!Exists(m => m.IMEI == imei))
|
||
{
|
||
Add(new WX_USERIMEI() { IMEI = imei, CTIME = DateTime.Now });
|
||
}
|
||
}
|
||
return true;
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public List<WX_USERIMEI> GetList(string imei, decimal? eid)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
var queryData = db.WX_USERIMEI.AsQueryable();
|
||
if (!string.IsNullOrWhiteSpace(imei))
|
||
{
|
||
imei = imei.Trim();
|
||
queryData = queryData.Where(m => m.IMEI == imei);
|
||
}
|
||
if (eid.HasValue && eid > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.EID == eid);
|
||
}
|
||
return queryData.OrderBy(m => m.EID).OrderByDescending(m => m.CTIME).ToList();
|
||
}
|
||
}
|
||
|
||
public bool Insert(ref ValidationErrors errors, string imei, decimal eid)
|
||
{
|
||
try
|
||
{
|
||
if (!Exists(m => m.IMEI == imei))
|
||
{
|
||
Add(new WX_USERIMEI() { IMEI = imei, EID = eid, CTIME = DateTime.Now });
|
||
}
|
||
else
|
||
{
|
||
errors.Add("手机IMEI已经存在");
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex);
|
||
errors.Add(ex.Message);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public bool Update(ref ValidationErrors errors, string imei, decimal eid)
|
||
{
|
||
try
|
||
{
|
||
var model = Get(m => m.IMEI == imei);
|
||
if (model != null)
|
||
{
|
||
model.EID = eid;
|
||
return Update(model);
|
||
}
|
||
else
|
||
{
|
||
errors.Add("修改失败,不存在该条imei记录");
|
||
return false;
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex);
|
||
errors.Add(ex.Message);
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
}
|