using System; using System.Collections.Generic; using System.Text; using System.Data; using WeiSha.Common; using Song.Entities; using WeiSha.Data; using Song.ServiceInterfaces; namespace Song.ServiceImpls { public class MessageCom : IMessage { /// /// 添加 /// /// 业务实体 public int Add(Message entity) { entity.Msg_CrtTime = DateTime.Now; Song.Entities.Organization org = Business.Do().OrganCurrent(); if (org != null) entity.Org_Id = org.Org_ID; return Gateway.Default.Save(entity); } /// /// 修改 /// /// 业务实体 public void Save(Message entity) { Gateway.Default.Save(entity); } /// /// 删除 /// /// 业务实体 public int Delete(Message entity) { return Gateway.Default.Delete(entity); } /// /// 删除,按主键ID; /// /// 实体的主键 public int Delete(int identify) { return Gateway.Default.Delete(Message._.Msg_Id == identify); } /// /// 删除,按主键id和学员id /// /// 主键id /// 学员账户id public int Delete(int identify, int acid) { return Gateway.Default.Delete(Message._.Msg_Id == identify && Message._.Ac_ID == acid); } /// /// 获取单一实体对象,按主键ID; /// /// 实体的主键 /// public Message GetSingle(int identify) { return Gateway.Default.From().Where(Message._.Msg_Id == identify).ToFirst(); } /// /// 获取对象; /// /// 课程id /// 章节id /// public Message[] GetAll(int couid, int olid) { return GetCount(couid, olid, "asc", 0); } public Message[] GetAll(int olid,string order) { return GetCount(0, olid, order, 0); } public Message[] GetCount(int couid, int olid, string order, int count) { WhereClip wc = new WhereClip(); if (couid > 0) wc &= Message._.Cou_ID == couid; if (olid > 0) wc &= Message._.Ol_ID == olid; OrderByClip ord = Message._.Msg_CrtTime.Asc; if ("desc".Equals(order, StringComparison.CurrentCultureIgnoreCase)) ord = Message._.Msg_CrtTime.Desc; if ("asc".Equals(order, StringComparison.CurrentCultureIgnoreCase)) ord = Message._.Msg_CrtTime.Asc; return Gateway.Default.From().Where(wc).OrderBy(ord).ToArray(count); } /// /// 获取留言数量 /// /// /// /// public int GetOfCount(int couid, int olid) { WhereClip wc = new WhereClip(); if (couid > 0) wc &= Message._.Cou_ID == couid; if (olid > 0) wc &= Message._.Ol_ID == olid; //Message._.Msg_Title return Gateway.Default.From().Where(wc).Count(); } /// /// 分页获取 /// /// /// /// /// /// 创建时间,起始范围 /// 创建时间,结束的范围 /// /// /// /// public Message[] GetPager(int couid, int olid, int stid, string sear, DateTime? startTime, DateTime? endTime, int size, int index, out int countSum) { WhereClip wc = new WhereClip(); if (couid > 0) wc &= Message._.Cou_ID == couid; if (olid > 0) wc &= Message._.Ol_ID == olid; if (stid > 0) wc &= Message._.Ac_ID == stid; if (!string.IsNullOrWhiteSpace(sear)) wc.And(Message._.Msg_Context.Like("%" + sear + "$")); if (startTime != null) { wc.And(Message._.Msg_CrtTime >= (DateTime)startTime); } if (endTime != null) { wc.And(Message._.Msg_CrtTime < (DateTime)endTime); } countSum = Gateway.Default.Count(wc); return Gateway.Default.From().Where(wc).OrderBy(Message._.Msg_CrtTime.Desc).ToArray(size, (index - 1) * size); } /// /// 分页获取 /// /// /// /// /// /// /// /// /// /// /// public Message[] GetPager(int couid, int olid, int stid, string sear, int startPlay, int endPlay, int size, int index, out int countSum) { WhereClip wc = new WhereClip(); if (couid > 0) wc &= Message._.Cou_ID == couid; if (olid > 0) wc &= Message._.Ol_ID == olid; if (stid > 0) wc &= Message._.Ac_ID == stid; if (!string.IsNullOrWhiteSpace(sear)) wc.And(Message._.Msg_Context.Like("%" + sear + "$")); if (startPlay >= 0) { wc.And(Message._.Msg_PlayTime >= startPlay); } if (endPlay >= 0) { wc.And(Message._.Msg_PlayTime < endPlay); } countSum = Gateway.Default.Count(wc); return Gateway.Default.From().Where(wc).OrderBy(Message._.Msg_CrtTime.Desc).ToArray(size, (index - 1) * size); } } }