public List <Org> SearchByGeo(string searchStr) { RedBloodDataContext db = new RedBloodDataContext(); searchStr = searchStr.Trim(); if (string.IsNullOrEmpty(searchStr)) { return((from c in db.Orgs select c).ToList()); } else { Geo g = GeoBLL.GetByFullname(searchStr); if (g == null) { return(new List <Org>()); } if (g.Level == 1) { return(db.Orgs.Where(r => r.GeoID1 == g.ID).ToList()); } if (g.Level == 2) { return(db.Orgs.Where(r => r.GeoID2 == g.ID && r.GeoID1 == g.ParentGeo.ID).ToList()); } if (g.Level == 3) { return(db.Orgs.Where(r => r.GeoID3 == g.ID && r.GeoID2 == g.ParentGeo.ID && r.GeoID1 == g.ParentGeo.ParentGeo.ID).ToList()); } return(new List <Org>()); } }
private static Guid?ImportPeople(RedBloodDataContext db, People outerP) { //Importing people if (outerP == null || db == null) { return(null); } People innerP = PeopleBLL.GetByID(outerP.ID); if (innerP == null) { People newP = new People(); newP.Name = outerP.Name; newP.DOB = outerP.DOB; newP.DOBYear = outerP.DOBYear; newP.CMND = outerP.CMND; newP.SexID = outerP.SexID; GeoBLL.Insert( outerP.ResidentGeo1 != null ? outerP.ResidentGeo1.Name : "" , outerP.ResidentGeo2 != null ? outerP.ResidentGeo2.Name : "" , outerP.ResidentGeo3 != null ? outerP.ResidentGeo3.Name : ""); newP.ResidentAddress = outerP.ResidentAddress; newP.SetResidentGeo3(outerP.FullResidentalGeo); if (outerP.EnableMailingAddress.HasValue && outerP.EnableMailingAddress.Value) { GeoBLL.Insert( outerP.MailingGeo1 != null ? outerP.MailingGeo1.Name : "" , outerP.MailingGeo2 != null ? outerP.MailingGeo2.Name : "" , outerP.MailingGeo3 != null ? outerP.MailingGeo3.Name : ""); newP.MailingAddress = outerP.MailingAddress; newP.SetMailingGeo3(outerP.FullMaillingGeo); newP.EnableMailingAddress = outerP.EnableMailingAddress; } newP.Job = outerP.Job; newP.Email = outerP.Email; newP.Phone = outerP.Phone; newP.Note = outerP.Note; db.Peoples.InsertOnSubmit(newP); db.SubmitChanges(); return(newP.ID); } else { return(innerP.ID); } }
public static void Set3LevelByFullname(string fullname, Func <Guid?, Guid?, Guid?, int> setGeoFunc) { if (string.IsNullOrEmpty(fullname) || string.IsNullOrEmpty(fullname.Trim())) { throw new Exception("Nhập đơn vị hành chính."); } else { Geo g = GeoBLL.GetByFullname(fullname); if (g == null) { throw new Exception("Nhập sai đơn vị hành chính."); } else { Guid?geo1ID = null; Guid?geo2ID = null; Guid?geo3ID = null; if (g.Level == 1) { geo1ID = g.ID; } if (g.Level == 2) { geo2ID = g.ID; geo1ID = g.ParentGeo.ID; } if (g.Level == 3) { geo3ID = g.ID; geo2ID = g.ParentGeo.ID; geo1ID = g.ParentGeo.ParentGeo.ID; } setGeoFunc(geo1ID, geo2ID, geo3ID); } } }