public int AddAffiliation(JabsomAffil newAffil) { _dbContext.JabsomAffils.Add(newAffil); _dbContext.SaveChanges(); return(newAffil.Id); }
protected void btnSave_Click(object sender, EventArgs e) { if (txtName.Value.Length < 10 || ddlCategoryEdit.SelectedValue == string.Empty) { return; } else { int affilId = 0; Int32.TryParse(lblAffilId.Text, out affilId); bool saved = false; var affil = _repository.GetAffiliationByName(txtName.Value); if (affilId > 0) { if (affil == null || affil.Id == affilId) { var affilEdit = new JabsomAffil() { Id = affilId, Name = txtName.Value }; saved = _repository.UpdateAffiliation(affilEdit); } } else { var newAffil = new JabsomAffil { Type = ddlCategoryEdit.SelectedValue, Name = txtName.Value }; if (affil != null) { Response.Write("<script>alert('Affiliation exists already!');</script>"); } else { saved = _repository.AddAffiliation(newAffil) > 0; } } ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ModalScript", PageUtility.LoadEditScript(false), false); List <JabsomAffil> affiliations = _repository.GetAffiliations(""); rptAffiliation.DataSource = affiliations; rptAffiliation.DataBind(); } }
public bool UpdateAffiliation(JabsomAffil affilEdit) { var affil = _dbContext.JabsomAffils.FirstOrDefault(a => a.Id == affilEdit.Id); if (affil.Name != affilEdit.Name) { affil.Name = affilEdit.Name; _dbContext.SaveChanges(); return(true); } else { return(false); } }
protected void rptAffiliation_ItemCommand(Object sender, RepeaterCommandEventArgs e) { if (((Button)e.CommandSource).Text.Equals("Edit")) { var arg = string.Format("{0}{1}{2}", "{", ((Button)e.CommandSource).CommandArgument, "}"); JabsomAffil affil = JsonConvert.DeserializeObject <JabsomAffil>(arg); if (affil != null) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ModalScript", PageUtility.LoadEditScript(true), false); lblAffilId.Text = affil.Id.ToString(); ddlCategoryEdit.SelectedValue = affil.Type; ddlCategoryEdit.Enabled = false; txtName.Value = affil.Name; } } }