public ActionResult Remove(int id) { AuthorTable author = db.AuthorTables.Find(id); db.AuthorTables.Remove(author); db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
private async Task UpdateAuthor(int authorId, AuthorTable author) { var currentAuthor = await this.dbContext.Authors.FirstOrDefaultAsync(a => a.AuthorId == authorId); currentAuthor.AuthorId = author.AuthorId; currentAuthor.AuthorName = author.AuthorName; currentAuthor.BookTableId = author.BookTableId; await dbContext.SaveChangesAsync(); }
public ActionResult Edit(int id) { if (ModelState.IsValid) { AuthorTable author = db.AuthorTables.Find(id); if (TryUpdateModel(author, "", new string[] { "AuthorName" })) { db.SaveChanges(); return(RedirectToAction("Index", "Home")); } } return(RedirectToAction("Index", "Home")); }
public ActionResult Create(AuthorViewModel viewModel) { if (ModelState.IsValid) { AuthorTable author = new AuthorTable(); author.AuthorName = viewModel.AuthorName1; db.AuthorTables.Add(author); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("About", "Home")); } }
void DeleteAuthor() { try { SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("Delete from dbo.author_master_tbl Where author_id='" + TextBox_AuthorId.Text.Trim() + "'", con); cmd.ExecuteNonQuery(); con.Close(); Response.Write("<script>alert('Author Deleted successfully);</script>"); ClearForm(); AuthorTable.DataBind(); } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }
void UpdateAuthor() { try { SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("Update dbo.author_master_tbl Set author_name=@author_name Where author_id='" + TextBox_AuthorId.Text.Trim() + "'", con); cmd.Parameters.AddWithValue("@author_name", TextBox_AuthorName.Text.Trim()); cmd.ExecuteNonQuery(); con.Close(); Response.Write("<script>alert('Author Updated Successfully');</script>"); AuthorTable.DataBind(); } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }
public ActionResult Edit(int?id) { if (Convert.ToBoolean(Session["IsAdmin"]) == true) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AuthorTable author = db.AuthorTables.Find(id); if (author == null) { return(HttpNotFound()); } return(View(author)); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult Detail(int?id) { if (Session["UserID"] != null) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AuthorTable author = db.AuthorTables.Find(id); if (author == null) { return(HttpNotFound()); } return(View(author)); } else { return(RedirectToAction("Index", "Home")); } }
void AddNewAuthor() { try{ SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("Insert Into dbo.author_master_tbl(author_id, author_name) values(@author_id, @author_name)", con); cmd.Parameters.AddWithValue("@author_id", TextBox_AuthorId.Text.Trim()); cmd.Parameters.AddWithValue("@author_name", TextBox_AuthorName.Text.Trim()); cmd.ExecuteNonQuery(); con.Close(); Response.Write("<script>alert('Author added Successfully');</script>"); ClearForm(); AuthorTable.DataBind(); } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }
protected void Page_Load(object sender, EventArgs e) { AuthorTable.DataBind(); }