TG.WXCRM.V4/BLL/Csvr/CSVR_MSGOPENACCOUNT_BL.cs

101 lines
3.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.Csvr;
using WX.CRM.Model.Entity;
namespace WX.CRM.BLL.Csvr
{
public class CSVR_MSGOPENACCOUNT_BL : ICSVR_MSGOPENACCOUNT, ICSVR_MSGOPENACCOUNT_Q
{
/// <summary>
/// 获取全部没阅读信息
/// </summary>
/// <returns></returns>
public List<CSVR_MSGOPENACCOUNT> GetNoIsViewOpenAccount()
{
using (crmContext db = new crmContext())
{
List<CSVR_MSGOPENACCOUNT> list = db.CSVR_MSGOPENACCOUNT.Where(p => p.ISVIEWED == 0).ToList();
return list;
}
}
#region
/// <summary>
/// 添加
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool Create(ref ValidationErrors errors, WX.CRM.Model.Entity.CSVR_MSGOPENACCOUNT model)
{
try
{
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
{
model.PKID = new SEQUENCES_BL().Seq_base_get();
model.CTIME = DateTime.Now;
db.CSVR_MSGOPENACCOUNT.Add(model);
return db.SaveChanges().GetResult();
}
}
catch (Exception ex)
{
errors.Add(ex.Message);
return false;
}
}
#endregion
/// <summary>
/// 获取最新没有阅读的n条数据
/// </summary>
/// <param name="userId">员工ID</param>
/// <param name="top">顶部多少条数据</param>
/// <returns></returns>
public List<CSVR_MSGOPENACCOUNT> GetListNewOpenAccount(decimal userId, int top = 10)
{
using (crmContext db = new crmContext())
{
List<CSVR_MSGOPENACCOUNT> list = db.CSVR_MSGOPENACCOUNT.OrderByDescending(m => m.CTIME).Take(top).ToList();
return list;
}
}
/// <summary>
/// 修改已读
/// </summary>
/// <returns></returns>
public bool UpdateIsView(ref ValidationErrors errors, string resid)
{
try
{
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
{
CSVR_MSGOPENACCOUNT model = db.CSVR_MSGOPENACCOUNT.OrderByDescending(m => m.CTIME).FirstOrDefault(m => m.RESID == resid && m.ISVIEWED != 1);
if (model == null)
model = db.CSVR_MSGOPENACCOUNT.OrderByDescending(m => m.CTIME).FirstOrDefault(m => m.RESID == resid);
if (model == null)
{
errors.Add("找不到数据!");
return false;
}
if (model.ISVIEWED == 1)
return true;
model.ISVIEWED = 1;
return db.SaveChanges().GetResult();
}
}
catch (Exception ex)
{
errors.Add(ex.Message);
return false;
}
}
}
}