public void AddLinkService(int OrgID, string lsID) { if(lsID==""||lsID==null) return; var ls = lsID.Split(','); var listSerID = new List<string>(); // Get old link list aready have in system var ls1=from m in _db.OrganisationLinkServices where m.OrgID==OrgID select m; var delList = new Dictionary<int,int>(); // push this list in oldList foreach (var item in ls1) { delList.Add(item.LinkID, item.SerID); } foreach (var id in ls) { // if not have, add the new link // else remove from the delete link var ser = _db.Services.Where(m => m.SerID.ToString() == id).SingleOrDefault(); if (ser != null) { // if this link don't exist yet, Add new var link = _db.OrganisationLinkServices.Where(m => m.SerID.ToString() == id && m.OrgID == OrgID).SingleOrDefault(); if (link == null) { var newLink = new OrganisationLinkService(); newLink.OrgID = OrgID; newLink.SerID = ser.SerID; newLink.Role = ""; _db.OrganisationLinkServices.InsertOnSubmit(newLink); _db.SubmitChanges(); } else delList.Remove(link.LinkID); } } // all old rest must delete foreach (var del in delList) { var oldLink = _db.OrganisationLinkServices.Where(m => m.LinkID == del.Key).SingleOrDefault(); _db.OrganisationLinkServices.DeleteOnSubmit(oldLink); } _db.SubmitChanges(); }
partial void DeleteOrganisationLinkService(OrganisationLinkService instance);
partial void UpdateOrganisationLinkService(OrganisationLinkService instance);
partial void InsertOrganisationLinkService(OrganisationLinkService instance);
private void detach_OrganisationLinkServices(OrganisationLinkService entity) { this.SendPropertyChanging(); entity.Service = null; }
private void attach_OrganisationLinkServices(OrganisationLinkService entity) { this.SendPropertyChanging(); entity.Organisation = this; }