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_APPLYPRIMARYNUMBER_BL : ICSVR_APPLYPRIMARYNUMBER, ICSVR_APPLYPRIMARYNUMBER_Q { #region 新增 /// /// 新增数据 /// /// /// public bool Create(ref ValidationErrors errors, WX.CRM.Model.Entity.CSVR_APPLYPRIMARYNUMBER model) { try { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { model.PKID = new SEQUENCES_BL().Seq_base_get(WX.CRM.Model.Enum.PKIDType.LargeTable); db.CSVR_APPLYPRIMARYNUMBER.Add(model); return db.SaveChanges().GetResult(); } } catch (Exception ex) { errors.Add(ex.Message); return false; } } #endregion #region 查询 public List GetList(ref Pager pager ) { using (var db = new WX.CRM.Model.Entity.crmContext()) { var queryData = db.CSVR_APPLYPRIMARYNUMBER.AsQueryable(); queryData = queryData.Where(p => p.CHECKSTATUS == 0).OrderByDescending(m => m.CTIME); PagerUtil.SetPager(ref queryData, ref pager); var obj = (from a in queryData select a ).ToList(); return obj; } } public List GetList(string resid) { using (var db = new WX.CRM.Model.Entity.crmContext()) { resid = resid.Trim(); var obj = (from a in db.CSVR_APPLYPRIMARYNUMBER select a ).Where(p => p.RESID == resid).ToList(); return obj; } } #endregion #region 修改 public bool UpdateStatus(ref ValidationErrors errors, CSVR_APPLYPRIMARYNUMBER model) { try { using (var db = new WX.CRM.Model.Entity.crmContext()) { var entry = db.CSVR_APPLYPRIMARYNUMBER.FirstOrDefault(m => m.PKID == model.PKID); if (entry == null) return false; entry.CHECKUSER = model.CHECKUSER; entry.CHECKTIME = DateTime.Now; entry.CHECKSTATUS = model.CHECKSTATUS; db.SaveChanges(); return true; } } 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_APPLYPRIMARYNUMBER entry = db.CSVR_APPLYPRIMARYNUMBER.FirstOrDefault(m => m.PKID == id); if (entry == null) { errors.Add("数据已经被删除!"); return false; } db.CSVR_APPLYPRIMARYNUMBER.Remove(entry); return db.SaveChanges().GetResult(); } } catch (Exception ex) { errors.Add(ex.Message); return false; } } #endregion } }