94 lines
3.1 KiB
C#
94 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using WX.CRM.BLL.Base;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Csvr;
|
|
using WX.CRM.Model.Entity;
|
|
|
|
namespace WX.CRM.BLL.Csvr
|
|
{
|
|
public class CSVR_TODAYRECORD_BL : ICSVR_TODAYRECORD_Q, ICSVR_TODAYRECORD
|
|
{
|
|
|
|
public WX.CRM.Model.Entity.CSVR_TODAYRECORD GetMode(string resId, decimal Eid, DateTime ctime)
|
|
{
|
|
try
|
|
{
|
|
using (crmContext db = new crmContext())
|
|
{
|
|
CSVR_TODAYRECORD model = (from a in db.CSVR_TODAYRECORD
|
|
join
|
|
b in db.RES_CUSTOMER on a.RESID equals b.RESID
|
|
where b.RESID == resId && a.SALESEID == Eid
|
|
select a
|
|
).OrderByDescending(p => p.TIMESTART).FirstOrDefault();
|
|
if (model != null)
|
|
{
|
|
DateTime? dt = model.TIMESTART.HasValue
|
|
? model.TIMESTART.Value.AddSeconds(Convert.ToDouble(model.TIMELENGTH ?? 0))
|
|
: (DateTime?)null;
|
|
if (dt.HasValue && dt.Value > ctime.AddMinutes(-30))
|
|
{
|
|
return model;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
return model;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex);
|
|
LogHelper.Error(resId + ":" + Eid);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public void AddListRecord(List<CSVR_TODAYRECORD> listModel)
|
|
{
|
|
using (var db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
var pkid = new SEQUENCES_BL();
|
|
foreach (var model in listModel)
|
|
{
|
|
|
|
model.PKID = pkid.Seq_base_get();
|
|
if (model.RECORDID == 0)
|
|
model.RECORDID = model.PKID;
|
|
db.CSVR_TODAYRECORD.Add(model);
|
|
}
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
|
|
public void AddListRecordUn(List<CSVR_TODAYRECORDUN> listModel)
|
|
{
|
|
using (var db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
var pkid = new SEQUENCES_BL();
|
|
foreach (var model in listModel)
|
|
{
|
|
|
|
model.PKID = pkid.Seq_base_get();
|
|
if (model.RECORDID == 0)
|
|
model.RECORDID = model.PKID;
|
|
db.CSVR_TODAYRECORDUN.Add(model);
|
|
}
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
|
|
public List<CSVR_TODAYRECORD> GetTodayRecordsByPkid(decimal pkid)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.CSVR_TODAYRECORD.Where(m => m.PKID > pkid).ToList();
|
|
}
|
|
}
|
|
}
|
|
}
|