140 lines
4.9 KiB
C#
140 lines
4.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Res;
|
|
using WX.CRM.Model.Entity;
|
|
|
|
namespace WX.CRM.BLL.Res
|
|
{
|
|
public class RES_CALLOUTCUSTOMER_BL : IRES_CALLOUTCUSTOMER
|
|
{
|
|
/// <summary>
|
|
/// 新增
|
|
/// </summary>
|
|
/// <param name="errors"></param>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public bool Create(ref ValidationErrors errors, RES_CALLOUTCUSTOMER model)
|
|
{
|
|
try
|
|
{
|
|
using (crmContext db = new crmContext())
|
|
{
|
|
var entry = db.RES_CALLOUTCUSTOMER.FirstOrDefault(m => m.RESID == model.RESID && m.CALLOUTTYPE == model.CALLOUTTYPE);
|
|
if (entry != null)
|
|
{
|
|
errors.Add("违反唯一性约束!");
|
|
return false;
|
|
}
|
|
model.CTIME = DateTime.Now;
|
|
db.RES_CALLOUTCUSTOMER.Add(model);
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="errors"></param>
|
|
/// <param name="resid"></param>
|
|
/// <param name="callType"></param>
|
|
/// <returns></returns>
|
|
public bool Delete(ref ValidationErrors errors, string resid, string callType)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
RES_CALLOUTCUSTOMER entry = db.RES_CALLOUTCUSTOMER.FirstOrDefault(m => m.RESID == resid && m.CALLOUTTYPE == callType);
|
|
if (entry == null)
|
|
{
|
|
errors.Add("数据已经被删除!");
|
|
return false;
|
|
}
|
|
db.RES_CALLOUTCUSTOMER.Remove(entry);
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex) { errors.Add(ex.Message); return false; }
|
|
}
|
|
|
|
public List<RES_CALLOUTCUSTOMER> GetList(string resid, ref Pager pager)
|
|
{
|
|
using (var db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
var queryData = db.RES_CALLOUTCUSTOMER.AsQueryable();
|
|
if (!string.IsNullOrWhiteSpace(resid))
|
|
queryData = queryData.Where(m => m.RESID == resid);
|
|
|
|
queryData = queryData.OrderByDescending(c => c.CTIME);
|
|
PagerUtil.SetPager<RES_CALLOUTCUSTOMER>(ref queryData, ref pager);
|
|
var query = from a in queryData
|
|
join x in db.CSVR_CALLOUTPARA on a.CALLOUTTYPE equals x.CALLOUTTYPE
|
|
select new
|
|
{
|
|
CALLOUTTYPE = a.CALLOUTTYPE,
|
|
CTIME = a.CTIME,
|
|
RESID = a.RESID,
|
|
CALLOUTNAME = x.CALLOUTNAME,
|
|
REASON = a.REASON
|
|
};
|
|
return query.ToList().Select(item => new WX.CRM.Model.Entity.RES_CALLOUTCUSTOMER
|
|
{
|
|
CALLOUTTYPE = item.CALLOUTTYPE,
|
|
CTIME = item.CTIME,
|
|
RESID = item.RESID,
|
|
CALLOUTNAME = item.CALLOUTNAME,
|
|
REASON = item.REASON
|
|
}).ToList();
|
|
}
|
|
}
|
|
|
|
public List<WX.CRM.Model.Entity.RES_CALLOUTCUSTOMER> GetByResIds(string[] resId, string callType)
|
|
{
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
return db.RES_CALLOUTCUSTOMER.Where(m => m.CALLOUTTYPE == callType).Where(p => resId.Contains(p.RESID)).ToList();
|
|
}
|
|
}
|
|
|
|
|
|
public bool IsCallOut(string resId, string callType)
|
|
{
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
return db.RES_CALLOUTCUSTOMER.Any(m => m.RESID == resId && m.CALLOUTTYPE == callType);
|
|
}
|
|
}
|
|
|
|
public bool CreateEntities(ref ValidationErrors errors, List<WX.CRM.Model.Entity.RES_CALLOUTCUSTOMER> entities)
|
|
{
|
|
try
|
|
{
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
|
|
foreach (var entity in entities)
|
|
{
|
|
db.RES_CALLOUTCUSTOMER.Add(entity);
|
|
}
|
|
|
|
bool result = db.SaveChanges().GetResult(); ;
|
|
return result;
|
|
|
|
}
|
|
}
|
|
catch (Exception ex) { errors.Add(ex.Message); return false; }
|
|
}
|
|
|
|
}
|
|
}
|