140 lines
5.0 KiB
C#
140 lines
5.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using WX.CRM.BLL;
|
|
using WX.CRM.IBLL.Wx;
|
|
using WX.CRM.Model.Entity;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
|
|
namespace WX.CRM.BLL.Wx
|
|
{
|
|
public class WX_BIZINFO_BL :DbContextRepository<WX_BIZINFO>, IWX_BIZINFO
|
|
{
|
|
public WX.CRM.Model.Entity.WX_BIZINFO GetModel(decimal pkid)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.WX_BIZINFO.Where(m => m.PKID == pkid).FirstOrDefault();
|
|
}
|
|
}
|
|
|
|
public List<WX_BIZINFO> GetList(ref Pager page, decimal isEmpty, string username, string num, string nickname, string mark, string resid, string stime, string etime)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var queryData = db.WX_BIZINFO.AsQueryable();
|
|
if (!string.IsNullOrWhiteSpace(username))
|
|
{
|
|
username = username.Trim();
|
|
queryData = queryData.Where(m => m.USERNAME.Contains(username));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(num))
|
|
{
|
|
num = num.Trim();
|
|
queryData = queryData.Where(m => m.ALIAS.Contains(num));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(nickname))
|
|
{
|
|
nickname = nickname.Trim();
|
|
queryData = queryData.Where(m => m.NICKNAME.Contains(nickname));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(mark))
|
|
{
|
|
mark = mark.Trim();
|
|
queryData = queryData.Where(m => m.CONREMARK.Contains(mark));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(resid))
|
|
{
|
|
resid = resid.Trim();
|
|
queryData = queryData.Where(m => m.RESID.Contains(resid));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(stime))
|
|
{
|
|
DateTime time1 = Convert.ToDateTime(stime);
|
|
queryData = queryData.Where(m => m.CTIME >= time1);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(etime))
|
|
{
|
|
DateTime time2 = Convert.ToDateTime(etime).AddDays(1);
|
|
queryData = queryData.Where(m => m.CTIME >= time2);
|
|
}
|
|
if (isEmpty == 0)
|
|
queryData = queryData.Where(m => m.RESID != null);
|
|
else if (isEmpty == 1)
|
|
queryData = queryData.Where(m => m.RESID == null);
|
|
|
|
queryData = queryData.OrderByDescending(m => m.USERNAME);
|
|
PagerUtil.SetPager<WX_BIZINFO>(ref queryData, ref page);
|
|
return queryData.ToList();
|
|
}
|
|
}
|
|
|
|
public bool Update(ref ValidationErrors errors, WX.CRM.Model.Entity.WX_BIZINFO model)
|
|
{
|
|
try
|
|
{
|
|
using (crmContext db = new crmContext())
|
|
{
|
|
WX_BIZINFO entry = db.WX_BIZINFO.FirstOrDefault(m => m.PKID == model.PKID);
|
|
if (entry == null)
|
|
{
|
|
errors.Add("找不到数据!");
|
|
return false;
|
|
}
|
|
entry.RESID = model.RESID;
|
|
entry.ALIAS = model.ALIAS;
|
|
entry.UTIME = DateTime.Now;
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool Delete(ref ValidationErrors errors, decimal id)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
WX_BIZINFO entry = db.WX_BIZINFO.FirstOrDefault(m => m.PKID == id);
|
|
if (entry == null)
|
|
{
|
|
errors.Add("数据不存在!");
|
|
return false;
|
|
}
|
|
db.WX_BIZINFO.Remove(entry);
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex) { errors.Add(ex.Message); return false; }
|
|
}
|
|
|
|
public List<WX.CRM.Model.QueryMap.WxUserNameResid> GetList(string[] Resids)
|
|
{
|
|
if (Resids == null)
|
|
return null;
|
|
List<WX.CRM.Model.QueryMap.WxUserNameResid> lis = new List<WX.CRM.Model.QueryMap.WxUserNameResid>();
|
|
|
|
using (var db = new crmContext())
|
|
{
|
|
var tlis = db.WX_BIZINFO.Where(p => Resids.Contains(p.RESID)).ToList();
|
|
lis = tlis.Select(c => new WX.CRM.Model.QueryMap.WxUserNameResid
|
|
{
|
|
username = c.USERNAME,
|
|
resid = c.RESID
|
|
}).ToList();
|
|
}
|
|
return lis;
|
|
}
|
|
}
|
|
}
|
|
|
|
|