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; namespace WX.CRM.BLL.Csvr { public class CSVR_VIPNUMBER_BL : ICSVR_VIPNUMBER_Q, ICSVR_VIPNUMBER { public List GetPagingData(ref Pager pager, string resId, string type) { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { var list = db.CSVR_VIPNUMBER.AsQueryable(); if (!string.IsNullOrWhiteSpace(resId)) { list = list.Where(p => p.RESID.Trim() == resId); } if (!string.IsNullOrWhiteSpace(type)) { list = list.Where(p => p.VIPTYPE == type); } list = list.OrderByDescending(p => p.CTIME); PagerUtil.SetPager(ref list, ref pager); return list.ToList(); } } public bool CreateEntities(ref ValidationErrors errors, List entities) { try { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { foreach (var entity in entities) { entity.PKID = new SEQUENCES_BL().Seq_base_get(); db.CSVR_VIPNUMBER.Add(entity); } bool result = db.SaveChanges().GetResult(); ; return result; } } catch (Exception ex) { errors.Add(ex.Message); return false; } } #region 添加 public bool Create(ref ValidationErrors errors, WX.CRM.Model.Entity.CSVR_VIPNUMBER 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_VIPNUMBER.Add(model); return db.SaveChanges().GetResult(); } } catch (Exception ex) { errors.Add(ex.Message); return false; } } #endregion #region 删除 public bool Delete(ref ValidationErrors errors, decimal id) { try { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { WX.CRM.Model.Entity.CSVR_VIPNUMBER entry = db.CSVR_VIPNUMBER.FirstOrDefault(m => m.PKID == id); if (entry == null) { errors.Add("数据已经被删除!"); return false; } db.CSVR_VIPNUMBER.Remove(entry); return db.SaveChanges().GetResult(); } } catch (Exception ex) { errors.Add(ex.Message); return false; } } #endregion public bool IsVipNumber(ref ValidationErrors errors, string resid, string line) { try { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { var entr = db.BAS_SUBCOMTYPE.FirstOrDefault(m => m.TYPECODE == "VipCusType" && m.EDITFORM == line); if (entr == null) { errors.Add("oh no,number is wrong !"); return false; } WX.CRM.Model.Entity.CSVR_VIPNUMBER entry = db.CSVR_VIPNUMBER.FirstOrDefault(m => m.RESID == resid && m.VIPTYPE == entr.SUBTYPECODE); if (entry == null) { return false; } else { return true; } } } catch (Exception ex) { LogHelper.Error(ex.ToString()); errors.Add("系统错误!"); return false; } } /// /// 是否存在 /// /// /// /// public List GetByResIds(string[] resId, string viptype) { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { return db.CSVR_VIPNUMBER.Where(m => m.VIPTYPE == viptype).Where(p => resId.Contains(p.RESID)).ToList(); } } } }