public int CreateUser(NewUserModel model) { int userid = 0; try { string strSQL = @" insert into useraccount(username,password,stationid) values(@username,@password,@stationid) SELECT SCOPE_IDENTITY() "; SqlParameter[] parms = new SqlParameter[]{ new SqlParameter("@username",SqlDbType.NVarChar,50), new SqlParameter("@password",SqlDbType.NVarChar,1024), new SqlParameter("@stationid",SqlDbType.Int), }; parms[0].Value = model.UserName; parms[1].Value = model.Password; parms[2].Value = model.StationID; using (var rdr = SqlHelper.ExecuteReader(SqlHelper.SQLConnectString, CommandType.Text, strSQL, parms)) { if (rdr.Read()) { userid = Convert.ToInt32(rdr[0]); } } } catch(Exception ex) { throw; } return userid; }
public ActionResult Add(NewUserModel model) { if (ModelState.IsValid) { new BLUser().CreateUser(model); } return RedirectToAction("Index"); }
public int CreateUser(NewUserModel user) { return daUser.CreateUser(user); }