public int AddSchool(SchoolAddRequest model, int userId) { int id = 0; string procName = "[dbo].[Schools_Insert]"; _data.ExecuteNonQuery(procName, inputParamMapper : delegate(SqlParameterCollection col) { AddCommonParams(model, col); col.AddWithValue("@CreatedBy", userId); SqlParameter idOut = new SqlParameter("@Id", SqlDbType.Int); idOut.Direction = ParameterDirection.Output; col.Add(idOut); }, returnParameters : delegate(SqlParameterCollection returnCollection) { object oId = returnCollection["@Id"].Value; int.TryParse(oId.ToString(), out id); }); return(id); }
private static void AddCommonParams(SchoolAddRequest model, SqlParameterCollection col) { col.AddWithValue("@LineOne", model.LineOne); col.AddWithValue("@LineTwo", model.LineTwo); col.AddWithValue("@City", model.City); col.AddWithValue("@Zip", model.Zip); col.AddWithValue("@StateId", model.StateId); col.AddWithValue("@Latitude", model.Latitude); col.AddWithValue("@Longitude", model.Longitude); col.AddWithValue("@TypeId", model.TypeId); col.AddWithValue("@Name", model.Name); col.AddWithValue("@Headline", model.Headline); col.AddWithValue("@Description", model.Description); col.AddWithValue("@Logo", model.Logo); col.AddWithValue("@Phone", model.Phone); col.AddWithValue("@SiteUrl", model.SiteUrl); col.AddWithValue("@DistrictId", model.DistrictId); }