public bool Create(Page page, out int id) { using (var cn = Connection) { using (var transaction = new TransactionScope()) { cn.Open(); var success = true; id = -1; var sql = "INSERT INTO `pages` (`Name`, `Title`, `Text`,`PageSection`) VALUES (@Name, @Title, @Text, @PageSection);"; success = cn.Execute(sql, page) > 0; var newId = cn.Query<ulong>("SELECT CAST(LAST_INSERT_ID() AS UNSIGNED INTEGER);").SingleOrDefault(); id = Convert.ToInt32(newId); transaction.Complete(); return success; } } }
public bool Delete(Page page) { using (var cn = Connection) { var sql = "DELETE FROM `id`=@ID;"; return cn.Execute(sql, page.ID) > 0; } }
public bool Update(Page page) { using (var cn = Connection) { var sql = "UPDATE `pages` SET `Name`=@Name, `Title`=@Title, `Text`=@Text,`PageSection`=@PageSection WHERE `id`=@ID;"; return cn.Execute(sql, page) > 0; } }
public bool Put(Page page) { using (var cn = Connection) { using (var transaction = new TransactionScope()) { cn.Open(); var success = true; var sql = "DELETE FROM `pages` WHERE `id`=@id;"; success &= cn.Execute(sql, new { id = page.ID }) > 0; if (success) { sql = "INSERT INTO `pages` (`ID`, `Name`, `Title`, `Text`,`PageSection`) VALUES (@ID, @Name, @Title, @Text, @PageSection);"; success &= cn.Execute(sql, page) > 0; } if (!success) transaction.Dispose(); else transaction.Complete(); return success; } } }