public void SaveTen(EduTendency edutendency) { using (PersonsDBEntities DC = conn.GetContext()) { if (edutendency.TendencyID > 0) { //==== UPDATE ==== DC.EduTendencies.Attach(edutendency); DC.Entry(edutendency).State = EntityState.Modified; } else { //==== INSERT ==== DC.EduTendencies.Add(edutendency); } DC.SaveChanges(); } }
protected void Button1_Click(object sender, EventArgs e) { VEduTendenciesRepository ten = new VEduTendenciesRepository(); if (ten.FindByTendencyTitle(TextBox1.Text) != null) { PersonTools.ShowMessage(lblmessage, Resources.DashboardText.errDuplicateUsername, Color.Red); return; } bool successfullCreateAccount = true; try { EduTendency newTendency = new EduTendency(); VEduTendenciesRepository ctrir = new VEduTendenciesRepository(); newTendency.TendencyTitle = TextBox1.Text.Trim(); newTendency.FieldID = ddlfield.SelectedValue.ToInt(); ctrir.SaveTen(newTendency); ClearForm(); } catch (System.Exception err) { successfullCreateAccount = false; PersonTools.ShowMessage(lblmessage, Resources.DashboardText.errAddFailed, Color.Red); } if (successfullCreateAccount) { // ClearForm(); PersonTools.ShowMessage(lblmessage, Resources.DashboardText.msgAddSuccessfull, Color.Green); } }