170 lines
5.7 KiB
C#
170 lines
5.7 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.Res;
|
|
using WX.CRM.Model.Entity;
|
|
|
|
namespace WX.CRM.BLL.Res
|
|
{
|
|
public class RES_SALESGROUP_BL : IRES_SALESGROUP, IRES_SALESGROUP_Q
|
|
{
|
|
public bool Create_ResSalesGroup(ref ValidationErrors errors, WX.CRM.Model.Entity.RES_SALESGROUP model)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
RES_SALESGROUP entity = GetModel_ResSalesGroupByName(model.NAME);
|
|
if (entity == null)
|
|
{
|
|
model.GROUPID = new SEQUENCES_BL().Seq_base_get();
|
|
db.RES_SALESGROUP.Add(model);
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
else
|
|
{
|
|
errors.Add("添加的客服资源分组名已存在!");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool Update_ResSalesGroup(ref ValidationErrors errors, WX.CRM.Model.Entity.RES_SALESGROUP model)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
RES_SALESGROUP entity = db.RES_SALESGROUP.FirstOrDefault(m => m.GROUPID == model.GROUPID);
|
|
if (entity != null)
|
|
{
|
|
entity.NAME = model.NAME;
|
|
entity.MEMO = model.MEMO;
|
|
db.SaveChanges();
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
errors.Add("待修改的客服资源分组不存在!");
|
|
return false;
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool Delete_ResSalesGroup(ref ValidationErrors errors, decimal id)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
RES_SALESGROUP entity = db.RES_SALESGROUP.FirstOrDefault(m => m.GROUPID == id);
|
|
if (entity == null)
|
|
{
|
|
errors.Add("数据不存在!");
|
|
return false;
|
|
}
|
|
db.RES_SALESGROUP.Remove(entity);
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public WX.CRM.Model.Entity.RES_SALESGROUP GetModel_ResSalesGroup(decimal id)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.RES_SALESGROUP.FirstOrDefault(m => m.GROUPID == id);
|
|
}
|
|
}
|
|
|
|
public WX.CRM.Model.Entity.RES_SALESGROUP GetModel_ResSalesGroupByName(string name)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.RES_SALESGROUP.FirstOrDefault(m => m.NAME == name);
|
|
}
|
|
}
|
|
|
|
public List<WX.CRM.Model.Entity.RES_SALESGROUP> GetList()
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.RES_SALESGROUP.OrderByDescending(m => m.CTIME).ToList<RES_SALESGROUP>();
|
|
}
|
|
}
|
|
|
|
public List<WX.CRM.Model.Entity.RES_SALESGROUP> GetList_ResSalesGroup(ref Pager pg, string name, string stime, string etime)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
IQueryable<RES_SALESGROUP> data = db.RES_SALESGROUP.AsQueryable<RES_SALESGROUP>();
|
|
if (!string.IsNullOrEmpty(name))
|
|
data = data.Where(m => m.NAME.Contains(name));
|
|
|
|
DateTime _stime;
|
|
DateTime _etime;
|
|
if (!string.IsNullOrEmpty(stime) && DateTime.TryParse(stime, out _stime))
|
|
data = data.Where(m => m.CTIME >= _stime);
|
|
if (!string.IsNullOrEmpty(etime) && DateTime.TryParse(etime, out _etime))
|
|
{
|
|
_etime = _etime.AddDays(1);
|
|
data = data.Where(m => m.CTIME < _etime);
|
|
}
|
|
|
|
if (pg.order == "desc")
|
|
{
|
|
switch (pg.sort)
|
|
{
|
|
case "NAME":
|
|
data = data.OrderByDescending(c => c.NAME);
|
|
break;
|
|
case "CTIME":
|
|
data = data.OrderByDescending(c => c.CTIME);
|
|
break;
|
|
default:
|
|
data = data.OrderByDescending(c => c.CTIME);
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
switch (pg.sort)
|
|
{
|
|
case "NAME":
|
|
data = data.OrderBy(c => c.NAME);
|
|
break;
|
|
case "CTIME":
|
|
data = data.OrderBy(c => c.CTIME);
|
|
break;
|
|
default:
|
|
data = data.OrderBy(c => c.CTIME); break;
|
|
}
|
|
}
|
|
PagerUtil.SetPager<RES_SALESGROUP>(ref data, ref pg);//分页
|
|
return data.ToList();
|
|
}
|
|
}
|
|
}
|
|
}
|