150 lines
5.3 KiB
C#
150 lines
5.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using WX.CRM.BLL.Base;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Sms;
|
|
using WX.CRM.Model.Entity;
|
|
|
|
namespace WX.CRM.BLL.Sms
|
|
{
|
|
public class SMS_MSGTEMPLATE_BL : ISMS_MSGTEMPLATE, ISMS_MSGTEMPLATE_Q
|
|
{
|
|
public bool Create(ref ValidationErrors errors, WX.CRM.Model.Entity.SMS_MSGTEMPLATE model)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
model.PKID = new SEQUENCES_BL().Seq_base_get();
|
|
model.CTIME = DateTime.Now;
|
|
db.SMS_MSGTEMPLATE.Add(model);
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool Update(ref ValidationErrors errors, WX.CRM.Model.Entity.SMS_MSGTEMPLATE model)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var entity = db.SMS_MSGTEMPLATE.FirstOrDefault(m => m.PKID == model.PKID);
|
|
if (entity != null)
|
|
{
|
|
entity.SUBTYPEID = model.SUBTYPEID;
|
|
entity.TITLE = model.TITLE;
|
|
entity.TEMPLATE = model.TEMPLATE;
|
|
entity.TPARAM = model.TPARAM;
|
|
entity.ISSHOW = model.ISSHOW;
|
|
entity.ISAUDITED = model.ISAUDITED;
|
|
entity.AUDITORID = model.AUDITORID;
|
|
entity.UPDATEUSER = model.UPDATEUSER;
|
|
entity.UTIME = model.UTIME;
|
|
db.SaveChanges();
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
errors.Add("添加的参数名已存在!");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool Delete(ref ValidationErrors errors, decimal id)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var entity = db.SMS_MSGTEMPLATE.FirstOrDefault(m => m.PKID == id);
|
|
if (entity == null)
|
|
{
|
|
errors.Add("数据不存在!");
|
|
return false;
|
|
}
|
|
db.SMS_MSGTEMPLATE.Remove(entity);
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public WX.CRM.Model.Entity.SMS_MSGTEMPLATE GetModel(decimal id)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.SMS_MSGTEMPLATE.FirstOrDefault(m => m.PKID == id);
|
|
}
|
|
}
|
|
|
|
public List<WX.CRM.Model.Entity.SMS_MSGTEMPLATE> GetList(ref Pager pager, decimal subtypeId, decimal isShow, decimal isCheck, string param, string title, string stime, string etime)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var queryData = db.SMS_MSGTEMPLATE.AsQueryable();
|
|
|
|
if (subtypeId > 0)
|
|
queryData = queryData.Where(q => q.SUBTYPEID == subtypeId);
|
|
if (isShow >= 0)
|
|
queryData = queryData.Where(q => q.ISSHOW == isShow);
|
|
if (isCheck >= 0)
|
|
queryData = queryData.Where(q => q.ISAUDITED == isCheck);
|
|
if (!string.IsNullOrEmpty(param))
|
|
queryData = queryData.Where(q => q.TPARAM.Contains(param));
|
|
if (!string.IsNullOrEmpty(title))
|
|
queryData = queryData.Where(q => q.TITLE.Contains(title));
|
|
|
|
DateTime time1;
|
|
DateTime time2;
|
|
if (!string.IsNullOrEmpty(stime))
|
|
{
|
|
time1 = Convert.ToDateTime(stime);
|
|
queryData = queryData.Where(q => q.CTIME >= time1);
|
|
}
|
|
if (!string.IsNullOrEmpty(etime))
|
|
{
|
|
time2 = Convert.ToDateTime(etime).AddDays(1);
|
|
queryData = queryData.Where(q => q.CTIME < time2);
|
|
}
|
|
queryData = queryData.OrderByDescending(q => q.CTIME);
|
|
PagerUtil.SetPager<SMS_MSGTEMPLATE>(ref queryData, ref pager);
|
|
return queryData.ToList();
|
|
}
|
|
}
|
|
public List<WX.CRM.Model.Entity.SMS_MSGTEMPLATE> GetList(decimal subTypeId)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.SMS_MSGTEMPLATE.Where(m => m.ISSHOW == 1 && m.ISAUDITED == 1 && m.SUBTYPEID == subTypeId).ToList<SMS_MSGTEMPLATE>();
|
|
}
|
|
}
|
|
|
|
public List<SMS_MSGTEMPLATE> GetList()
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.SMS_MSGTEMPLATE.ToList<SMS_MSGTEMPLATE>();
|
|
}
|
|
}
|
|
}
|
|
}
|