public void Insert(Member member) { using (SqlConnection connection = new SqlConnection(GetConnection())) { connection.Execute( @"INSERT INTO Member (FirstName,Surname,MemberNumber,DateCreated) VALUES(@FirstName,@Surname,@MemberNumber,@DateCreated)", new { member.FirstName, member.Surname, member.MemberNumber, member.DateCreated }); }; }
public void Update(Member member) { using (SqlConnection connection = new SqlConnection(GetConnection())) { connection.Execute( @"Update Member SET [FirstName] = @FirstName,[Surname] = @Surname WHERE Member.Id = @Id", new { @FirstName = member.FirstName, @Surname = member.Surname, @Id = member.Id }); }; // public void Update(Movie movie) //{ // var sql = "UPDATE myDB.movies set title=@param1, genre=@param2 where ID=@param3"; // db.Execute(sql, new { param1 = movie.Title, param2 = movie.Genre, param3 = movie.ID }); //} }
public ActionResult Create(Member member) { try { Repository repo = new Repository(); if (ModelState.IsValid) { repo.Insert(member); } return RedirectToAction("Index"); } catch(Exception ex) { return View(); } }
public ActionResult Edit(int id, Member member) { try { Repository repo = new Repository(); repo.Update(member); return RedirectToAction("Index"); } catch(Exception ex) { return View(); } }