How to call stored procedure in MVC Application

How to call stored procedure in MVC Application


public int UpdateFinalOutcome(bool isDeathCertificate, bool isCornerReferralComplete)
{
int retVal = 0;
SqlCommand dbCommand = new SqlCommand("usp_UpsertFinalOutcome", connection);
            try
            {
                dbCommand.CommandType = CommandType.StoredProcedure;
                dbCommand.Parameters.AddWithValue("@isDeathCertificate", isDeathCertificate);
                dbCommand.Parameters.AddWithValue("@isCornerReferralComplete", isCornerReferralComplete);
retVal = dbCommand.ExecuteNonQuery();
catch (Exception ex)
            {
                LogException(ex.Message, this.ToString(), "ValidateUser", System.DateTime.Now);
            }
            return retVal;
        }

public List<clsPatientDetails> GetPatientDetails(int? patientID, int userID)
        {
            var connection = GetConnection();
            SqlDataReader dbReader = null;
            List<clsPatientDetails> lstPatientDetails = new List<clsPatientDetails>();
            try
            {
                SqlCommand dbCmd = new SqlCommand("usp_GetPatientDashboardDetails", connection);
                dbCmd.CommandType = CommandType.StoredProcedure;
                if (patientID != null)
                    dbCmd.Parameters.AddWithValue("@PatientID", patientID);
                else
                    dbCmd.Parameters.AddWithValue("@PatientID", 0);
                dbCmd.Parameters.AddWithValue("@UserID", userID);

                dbReader = dbCmd.ExecuteReader();
                while (dbReader.Read())
                {
                    clsPatientDetails patientDashboard = new clsPatientDetails();
                    if (string.IsNullOrEmpty(dbReader["ID"].ToString()))
                        patientDashboard.ID = 0;
                    else
                        patientDashboard.ID = Convert.ToInt32(dbReader["ID"]);
                    if (string.IsNullOrEmpty(dbReader["PatientId"].ToString()))
                        patientDashboard.PatientId = "";
                    else
                        patientDashboard.PatientId = Convert.ToString(dbReader["PatientId"]);
                    if (string.IsNullOrEmpty(dbReader["DOB"].ToString()))
                        patientDashboard.DOB = "Pending";
                    else
                        patientDashboard.DOB = Convert.ToDateTime(dbReader["DOB"]).ToString("dd/MM/yyyy");
                   
                    lstPatientDetails.Add(patientDashboard);
                }
                LogException("After loop", this.ToString(), "ValidateUser", System.DateTime.Now);
            }
            catch (Exception ex)
            {
                LogException(ex.Message, this.ToString(), "ValidateUser", System.DateTime.Now);
            }
            finally
            {
                if (!dbReader.IsClosed)
                    dbReader.Close();
            }
            return lstPatientDetails;
        }

Comments

Popular posts from this blog

Kendo Control(Dynamics)

Override Authorize Filters in MVC

Form Validation