125 lines
3.3 KiB
C#
125 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
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_ACCOUNT_BL : ISMS_ACCOUNT_Q, ISMS_ACCOUNT
|
|
{
|
|
|
|
#region 添加
|
|
public bool Create(ref ValidationErrors errors, SMS_ACCOUNT model)
|
|
{
|
|
try
|
|
{
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
db.SMS_ACCOUNT.Add(model);
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取单个
|
|
public SMS_ACCOUNT GetModel_SmsAccount(string code)
|
|
{
|
|
using (var db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
code = code.Trim();
|
|
return db.SMS_ACCOUNT.FirstOrDefault(p => p.CLIENTCODE.Trim() == code);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 编辑
|
|
public bool Update(ref ValidationErrors errors, SMS_ACCOUNT model)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
db.SMS_ACCOUNT.Attach(model);
|
|
db.Entry<SMS_ACCOUNT>(model).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region 删除
|
|
|
|
/// <summary>
|
|
/// 删除数据
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public bool Delete(ref ValidationErrors errors, string code)
|
|
{
|
|
try
|
|
{
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
code = code.Trim();
|
|
SMS_ACCOUNT userInfo = db.SMS_ACCOUNT.FirstOrDefault(m => m.CLIENTCODE == code);
|
|
if (userInfo != null)
|
|
db.SMS_ACCOUNT.Remove(userInfo);
|
|
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
|
|
}
|
|
catch (Exception ex) { errors.Add(ex.Message); return false; }
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 查询
|
|
|
|
public List<SMS_ACCOUNT> GetList()
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.SMS_ACCOUNT.ToList();
|
|
}
|
|
|
|
}
|
|
|
|
public List<SMS_ACCOUNT> GetList(decimal msgSubTypeId)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var q = from a in db.SMS_ACCOUNT
|
|
orderby a.SORTNO ascending
|
|
join sub in db.SMS_MSGTYPE_CLIENT on a.CLIENTCODE equals sub.CLIENTCODE
|
|
where sub.SUBTYPEID == msgSubTypeId
|
|
select a;
|
|
return q.ToList();
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
}
|
|
}
|