public static bool ProposeCheevo(string user, string proposes, int id)
{
bool ret = false;
bool dbOpened = false;
// complete it
const string completeIt = "update popped_cheevos set SecondMod = @user, AwardedTime = @awarded where CheevoID = @cheevoID and User = @proposes";
// add it
const string addIt = "insert into popped_cheevos (ID, CheevoID, User, ProposedTime, FirstMod) VALUES (NULL, @id, @proposes, @time, @user)";
lock (sqliteCon)
{
try
{
string cmd;
if (CheevoAlreadyProposed(proposes, id))
{
cmd = completeIt;
}
else
{
cmd = addIt;
}
sqliteCon.Open();
dbOpened = true;
using (SQLiteTransaction sqlTransaction = sqliteCon.BeginTransaction())
{
using (SQLiteCommand command = new SQLiteCommand(cmd, sqliteCon, sqlTransaction))
{
if (cmd == completeIt)
{
command.Parameters.AddWithValue("@user", user);
command.Parameters.AddWithValue("@awarded", DateTime.Now.Ticks);
command.Parameters.AddWithValue("@cheevoID", id);
command.Parameters.AddWithValue("@proposes", proposes);
}
else
{
command.Parameters.AddWithValue("@id", id);
command.Parameters.AddWithValue("@proposes", proposes);
command.Parameters.AddWithValue("@time", DateTime.Now.Ticks);
command.Parameters.AddWithValue("@user", user);
}
try
{
command.ExecuteNonQuery();
sqlTransaction.Commit();
ret = true;
}
catch
{
// do nothing, cheevo already added
}
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message + " " + ex.StackTrace);
}
finally
{
if (dbOpened)
{
Database.sqliteCon.Close();
}
}
}
return ret;
}