我正在使用MVP模式,并且在演示者中处理异常。诸如"Update Successful", "No matching records in DB"
等用户消息将由演示者可用的单独UserMassage服务类生成。 (由于消息传递是演示者的责任)
所以我只想知道演示者如何知道DAL方法是更新/删除了行还是失败了?
我目前的方法显示在DataService
类
public void DeletePoint(string pid)
{
string updateStatement = "IF NOT EXISTS (SELECT PID FROM Attendance WHERE PID = @pid )" +
"UPDATE Point SET Point.deleted = GETDATE() WHERE PID = @pid";
using (SqlConnection sqlConnection = new SqlConnection(db.ConnectionString))
using (SqlCommand sqlCommand = new SqlCommand(updateStatement, sqlConnection))
{
sqlCommand.Parameters.Add("@pid", SqlDbType.VarChar).Value = pid;
sqlConnection.Open();
var RowsAffected = sqlCommand.ExecuteNonQuery();
if (RowsAffected > 0)
{
throw new Exception("Updated Sucessfully");
}
Else
{
throw new Exception("Update was not Successful");
}
}
}