/// <summary> /// Get a list addresses by Individual ID /// </summary> /// <param name="individualId"></param> /// <returns>List<Address></returns> protected List <Address> GetAddressByIndividual(int individualId) { try { DBContext = new IWTestEntities(); return((from a in DBContext.Address join ia in DBContext.IndividualAddress on a.id equals ia.AddressId where ia.IndividualId == individualId select a).ToList()); } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "alert('" + ex.Message + "');", true); return(null); } }
/// <summary> /// Load Individual list and refresh update panel /// </summary> private void LoadIndividuals() { try { DBContext = new IWTestEntities(); var Individuals = DBContext.Individual.ToList(); IndividualsGridView.DataSource = Individuals; IndividualsGridView.DataBind(); UpdatePanelGrid.Update(); IndividualsGridView.HeaderRow.TableSection = TableRowSection.TableHeader; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script2", "initTable();", true); } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "alert('" + ex.Message + "');", true); } }
/// <summary> /// Merge individuals deleting the second one /// and adding its addresses to the first one /// </summary> /// <param name="individualId1">Id of the first Individual</param> /// <param name="individualId2">Id of the second Individual</param> protected void MergeIndividuals(int individualId1, int individualId2) { try { DBContext = new IWTestEntities(); DBContext.IndividualAddress.Where(x => individualId2 == x.IndividualId).ToList() .ForEach(a => a.IndividualId = individualId1); var ind = (from y in DBContext.Individual where y.id == individualId2 select y).FirstOrDefault(); DBContext.Individual.Remove(ind); DBContext.SaveChanges(); } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "alert('" + ex.Message + "');", true); } }