private static void AddParameters(OwnerAddRequest model, SqlParameterCollection col) { col.AddWithValue("@FirstName", model.FirstName); col.AddWithValue("@LastName", model.LastName); col.AddWithValue("@Password", model.Password); col.AddWithValue("@Email", model.Email); }
public ActionResult Add(OwnerAddRequest model) { ActionResult result = null; try { int id = _service.Add(model); result = Created201(id); } catch (Exception ex) { result = StatusCode(500, ex.ToString()); } return(result); }
public int Add(OwnerAddRequest model) { //Pass in OwnerAddRequestModel and a userId to record in db. TODO string procName = "[dbo].[Owner_Insert]"; int id = 0; var hashedPwd = BCrypt.Net.BCrypt.HashPassword(model.Password); model.Password = hashedPwd; _data.Add(procName, paramMapper: delegate (SqlParameterCollection col) { AddParameters(model, col); var idOut = new SqlParameter("@Id", SqlDbType.Int); idOut.Direction = ParameterDirection.Output; col.Add(idOut); }, returnParams: delegate (SqlParameterCollection returnColl) { var oId = returnColl["@Id"].Value; Int32.TryParse(oId.ToString(), out id); }); return id; }