/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public UserModel CreateUser(UserModel param) { try { if (param != null) { using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings[""].ConnectionString)) { connection.Open(); var cmd = connection.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "TestApp_UserCreate"; cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = param.Name; cmd.Parameters.Add("@DateOfBirth", SqlDbType.Date).Value = param.DateOfBirth.Date; if (param.IdentityCard != null) cmd.Parameters.Add("@IdentityCard", SqlDbType.NVarChar).Value = param.IdentityCard; if (param.Nickname != null) cmd.Parameters.Add("@Nickname", SqlDbType.NVarChar).Value = param.IdentityCard; cmd.Parameters.Add("@Email", SqlDbType.NVarChar).Value = param.Email; cmd.Parameters.Add("@Gender", SqlDbType.Bit).Value = param.Gender == Sex.Female ? 1 : 0; if (param.Marital != MaritalStatus.NotDefined) cmd.Parameters.Add("@MaritalStatusID", SqlDbType.SmallInt).Value = (short)param.Marital; if (param.NumberOfChildren != null) cmd.Parameters.Add("@NumberOfChildren", SqlDbType.SmallInt).Value = param.NumberOfChildren; cmd.Parameters.Add("@UserID", SqlDbType.Int).Direction = ParameterDirection.Output; var res = cmd.ExecuteNonQuery(); if (res > 0) { result = param; result.ObjectID = (int)cmd.Parameters["@UserID"].Value; } } } return result; } catch(Exception ex) { } }