public static bool Update(MB_Pipeline.Controllers.Models.Contact contact) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "[dbo].[usp_UpdateContact]"; cmd.Parameters.Add("id", System.Data.SqlDbType.Int).Value = contact.id; cmd.Parameters.Add("title", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(contact.title) ? contact.title : DBNull.Value.ToString()); cmd.Parameters.Add("name", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(contact.name) ? contact.name : DBNull.Value.ToString()); cmd.Parameters.Add("address", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(contact.address) ? contact.address : DBNull.Value.ToString()); cmd.Parameters.Add("address_line2", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(contact.address_line2) ? contact.address_line2 : DBNull.Value.ToString()); cmd.Parameters.Add("state", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(contact.state) ? contact.state : DBNull.Value.ToString()); cmd.Parameters.Add("zip_code", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(contact.zip_code) ? contact.zip_code : DBNull.Value.ToString()); cmd.Parameters.Add("email", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(contact.email) ? contact.email : DBNull.Value.ToString()); cmd.Parameters.Add("country", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(contact.country) ? contact.country : DBNull.Value.ToString()); cmd.Parameters.Add("phone_number", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(contact.phone_number) ? contact.phone_number : DBNull.Value.ToString()); cmd.Parameters.Add("secondary_number", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(contact.secondary_number) ? contact.secondary_number : DBNull.Value.ToString()); cmd.Parameters.Add("city", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(contact.city) ? contact.city : DBNull.Value.ToString()); if (Helper.SqlHelper.ExecuteQuery(cmd)) { return true; } return false; } }
public static bool New(MB_Pipeline.Controllers.Models.Location location, int account) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "[dbo].[usp_NewAccountLocation]"; cmd.Parameters.Add("account", System.Data.SqlDbType.Int).Value = account; cmd.Parameters.Add("address", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.address) ? location.address : DBNull.Value.ToString()); cmd.Parameters.Add("address_line2", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.address_line2) ? location.address_line2 : DBNull.Value.ToString()); cmd.Parameters.Add("state", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.state) ? location.state : DBNull.Value.ToString()); cmd.Parameters.Add("zip_code", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.zip_code) ? location.zip_code : DBNull.Value.ToString()); //cmd.Parameters.Add("country", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.country) ? location.country : DBNull.Value.ToString()); cmd.Parameters.Add("city", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.city) ? location.city : DBNull.Value.ToString()); cmd.Parameters.Add("location_type", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.location_type) ? location.location_type : DBNull.Value.ToString()); cmd.Parameters.Add("role", System.Data.SqlDbType.Int).Value = Helper.Sessions.GetUserFromSession().ID; var l = Helper.SqlHelper.ReadQuery<int>(cmd); if (l.Count > 0) { location.id = l[0]; Helper.MapsHelper.UpdateCords(location); return true; } return false; } }
public static bool UpdateCords(MB_Pipeline.Controllers.Models.Location location) { var address = location.address.Replace(' ', '+') + ',' + location.city.Replace(' ', '+') + ',' + location.state.Replace(' ', '+') + ' ' + location.zip_code; var result = get_coords_service(address); var obj = JsonConvert.DeserializeObject<GoogleGeoCodeResponse>(result); var r = false; using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "[dbo].[usp_updateAddGeoCodes]"; cmd.Parameters.Add("location_id", System.Data.SqlDbType.Int).Value = location.id; cmd.Parameters.Add("lat", System.Data.SqlDbType.NVarChar).Value = obj.results[0].geometry.location.lat; cmd.Parameters.Add("long", System.Data.SqlDbType.NVarChar).Value = obj.results[0].geometry.location.lng; r = MB_Pipeline.Helper.SqlHelper.ExecuteQuery(cmd); } return r; }
public static bool Update(MB_Pipeline.Controllers.Models.Location location) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "[dbo].[usp_UpdateLocation]"; cmd.Parameters.Add("id", System.Data.SqlDbType.Int).Value = location.id; cmd.Parameters.Add("name", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.name) ? location.name : DBNull.Value.ToString()); cmd.Parameters.Add("address", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.address) ? location.address : DBNull.Value.ToString()); cmd.Parameters.Add("address_line2", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.address_line2) ? location.address_line2 : DBNull.Value.ToString()); cmd.Parameters.Add("state", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.state) ? location.state : DBNull.Value.ToString()); cmd.Parameters.Add("zip_code", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.zip_code) ? location.zip_code : DBNull.Value.ToString()); //cmd.Parameters.Add("country", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.country) ? location.country : DBNull.Value.ToString()); cmd.Parameters.Add("city", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.city) ? location.city : DBNull.Value.ToString()); //cmd.Parameters.Add("location_type", System.Data.SqlDbType.NVarChar).Value = (!string.IsNullOrEmpty(location.location_type) ? location.location_type : DBNull.Value.ToString()); //cmd.Parameters.Add("role", System.Data.SqlDbType.Int).Value = Helper.Sessions.GetUserFromSession().ID; if (Helper.SqlHelper.ExecuteQuery(cmd)) { Helper.MapsHelper.UpdateCords(location); return true; } return false; } }