public ChurchReview Create(ChurchReview model) { var churchReview = new ChurchReview(); using (var dbconn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString)) { if (dbconn.State == ConnectionState.Open) { dbconn.Close(); } dbconn.Open(); using (var cmd = new SqlCommand("spInsertChurchReview", dbconn)) { try { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@userID", model.UserId); cmd.Parameters.AddWithValue("@simbahanID", model.SimbahanId); cmd.Parameters.AddWithValue("@name", model.Name); cmd.Parameters.AddWithValue("@title", ""); cmd.Parameters.AddWithValue("@rate", model.StarCount); cmd.Parameters.AddWithValue("@content", model.Comment); var reader = cmd.ExecuteReader(); while (reader.Read()) { churchReview = _churchReviewTransformer.Transform(reader); if (churchReview.UserId != 0) { churchReview.User = _userTransformer.Transform(reader); } churchReview.Simbahan = _churchTransformer.Transform(reader); } } catch (Exception) { // ignored } } } return(churchReview); }
public ChurchReview Create(ChurchReview model) { var churchReview = new ChurchReview(); using (var sp = new StoredProcedure("spInsertChurchReview")) { sp.SqlCommand.Parameters.AddWithValue("@userID", model.UserId); sp.SqlCommand.Parameters.AddWithValue("@simbahanID", model.SimbahanId); sp.SqlCommand.Parameters.AddWithValue("@title", model.Title); sp.SqlCommand.Parameters.AddWithValue("@rate", model.StarCount); sp.SqlCommand.Parameters.AddWithValue("@content", model.Comment); var reader = sp.SqlCommand.ExecuteReader(); while (reader.Read()) { churchReview = _churchReviewTransformer.Transform(reader); churchReview.User = _userTransformer.Transform(reader); churchReview.Simbahan = _churchTransformer.Transform(reader); } } return(churchReview); }