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_UNITECUSTOMERAPPLYDETAIL_BL : ICSVR_UNITECUSTOMERAPPLYDETAIL, ICSVR_UNITECUSTOMERAPPLYDETAIL_Q { public bool Creata_UnitCustomerApplyDetail(ref ValidationErrors errors, List lists, decimal uniteID) { try { using (crmContext db = new crmContext()) { foreach (CustomerRelation cr in lists) { var cust = db.RES_CUSTOMER.FirstOrDefault(n => n.RESID == cr.resId || n.UMID == cr.resId); var newcust = db.RES_CUSTOMER.FirstOrDefault(n => n.RESID == cr.newCustomerid || n.UMID == cr.newCustomerid); CSVR_UNITECUSTOMERAPPLYDETAIL detailModel = new CSVR_UNITECUSTOMERAPPLYDETAIL { PKID = new SEQUENCES_BL().Seq_base_get(), UNITEID = uniteID, RESID = cust?.RESID, UMID = cust?.UMID, NEWCUSTOMERID = newcust?.RESID, NEWUMID = newcust?.UMID }; var oldcust = db.RES_CUSTOMER.FirstOrDefault(n => n.RESID == cr.oldCustomerid || n.UMID == cr.oldCustomerid); if (oldcust == null) { detailModel.OLDCUSTOMERID = cust?.CUSTOMERID; } else { detailModel.OLDUMID = oldcust?.UMID; detailModel.OLDCUSTOMERID = oldcust?.RESID; } db.CSVR_UNITECUSTOMERAPPLYDETAIL.Add(detailModel); } return db.SaveChanges().GetResult(); } } catch (Exception ex) { errors.Add(ex.Message); return false; } } public List GetList_UniteCustomerApplyDetail(decimal uniteid) { using (crmContext db = new crmContext()) { return db.CSVR_UNITECUSTOMERAPPLYDETAIL.Where(m => m.UNITEID == uniteid).OrderBy(m => m.NEWCUSTOMERID).ToList(); } } } }