public static ResponseBase CreateOrUpdate(SC_STUDENT student) { ResponseBase baseResponse = new ResponseBase(); using (SqlConnection sqlConnection = new SqlConnection(Connection.SchoolDB)) { string procedureName = "PROC_STUDENT_INSERT_OR_UPDATE"; SqlCommand sqlCommand = new SqlCommand(procedureName, sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@V_STD_ID", Utility.UGuid.GuidOrNull(student.STD_ID)); sqlCommand.Parameters.AddWithValue("@V_STD_NAME", student.STD_NAME); sqlCommand.Parameters.AddWithValue("@V_STD_LAST_NAME", student.STD_LAST_NAME); sqlCommand.Parameters.AddWithValue("@V_STD_BIRTH_DATE", student.STD_BIRTH_DATE); sqlCommand.Parameters.AddWithValue("@V_STD_IMAGE", student.STD_IMAGE); sqlCommand.Parameters.AddWithValue("@V_STD_EMAIL", student.STD_EMAIL); sqlCommand.Parameters.AddWithValue("@V_STD_ACTIVE", student.STD_ACTIVE); sqlCommand.Parameters.Add(ResponseBase.IS_SUCCESS_PARAMETER, SqlDbType.Bit, int.MaxValue).Direction = System.Data.ParameterDirection.Output; sqlCommand.Parameters.Add(ResponseBase.STATUS_CODE_PARAMETER, SqlDbType.VarChar, 10).Direction = System.Data.ParameterDirection.Output; sqlCommand.Parameters.Add(ResponseBase.STATUS_MESSAGE_PARAMETER, SqlDbType.VarChar, 350).Direction = System.Data.ParameterDirection.Output; sqlCommand.Parameters.Add(ResponseBase.GENERATED_ID_PARAMETER, SqlDbType.UniqueIdentifier, int.MaxValue).Direction = System.Data.ParameterDirection.Output; try { sqlConnection.Open(); sqlCommand.ExecuteNonQuery(); baseResponse.IsSuccess = Convert.ToBoolean(sqlCommand.Parameters[ResponseBase.IS_SUCCESS_PARAMETER].Value); baseResponse.StatusCode = Convert.ToString(sqlCommand.Parameters[ResponseBase.STATUS_CODE_PARAMETER].Value); baseResponse.Message = Convert.ToString(sqlCommand.Parameters[ResponseBase.STATUS_MESSAGE_PARAMETER].Value); if (baseResponse.IsSuccess) { student.STD_ID = Guid.Parse(Convert.ToString(sqlCommand.Parameters[ResponseBase.GENERATED_ID_PARAMETER].Value)); baseResponse.Data = student; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } finally { if (!(sqlConnection is null)) { sqlConnection.Close(); } } } return(baseResponse); }
public JsonResult CreateOrUpdate(SC_STUDENT student) { ResponseBase responseBase = DataAccess.StudentAccess.CreateOrUpdate(student); return(new JsonResult(responseBase)); }