protected void butSubmit_Click(object sender, EventArgs e) { int playerId = int.Parse(Request.QueryString["player"]); MlbDataContext mlbData = new MlbDataContext(); CONTRACT con = (from c in mlbData.CONTRACTs where c.Player == playerId select c).SingleOrDefault(); if (con == null) { con = new CONTRACT(); con.Player = playerId; mlbData.CONTRACTs.InsertOnSubmit(con); } con.YearSigned = int.Parse(drpYearSigned.Text); mlbData.SubmitChanges(); foreach (string key in Request.Form.Keys) { int index = key.IndexOf("Salary"); if (index >= 0) { int year = int.Parse(key.Substring(index + 6)); var conYear = (from cy in mlbData.CONTRACT_YEARs where cy.Contract == con.CONTRACT_ID && cy.Year == year select cy).SingleOrDefault(); if (conYear == null) { conYear = new CONTRACT_YEAR(); conYear.Contract = con.CONTRACT_ID; conYear.Year = year; mlbData.CONTRACT_YEARs.InsertOnSubmit(conYear); } conYear.Salary = decimal.Parse(Request.Form[key]); } } mlbData.SubmitChanges(); }
partial void DeleteCONTRACT_YEAR(CONTRACT_YEAR instance);
partial void InsertCONTRACT_YEAR(CONTRACT_YEAR instance);
partial void UpdateCONTRACT_YEAR(CONTRACT_YEAR instance);
private void detach_CONTRACT_YEARs(CONTRACT_YEAR entity) { this.SendPropertyChanging(); entity.CONTRACT1 = null; }