private List <CordenatesModel> Load(DataSet data) { List <CordenatesModel> cordenates; CordenatesModel cordenate; try { cordenates = new List <CordenatesModel>(); foreach (DataRow row in data.Tables[0].Rows) { cordenate = new CordenatesModel(); cordenate.ID = row.Field <int>("ID"); cordenate.ID_end = row.Field <int>("ID_end"); cordenate.Latitude = row.Field <string>("Latitude"); cordenate.Longitude = row.Field <string>("Longitude"); cordenates.Add(cordenate); } } catch (Exception ex) { throw ex; } return(cordenates); }
public CordenatesModel Update(CordenatesModel Cordenate) { SqlHelper dataConnection; SqlCommand command; try { dataConnection = new SqlHelper(_loggerFactory, _config); command = new SqlCommand($@"UPDATE cordenadas SET ID_end ,Latitude ,Longitude WHERE ID = @ID" ); command.Parameters.AddWithValue("ID", Cordenate.ID.AsDbValue()); command.Parameters.AddWithValue("Latitude", Cordenate.Latitude.AsDbValue()); command.Parameters.AddWithValue("Longitude", Cordenate.Longitude.AsDbValue()); dataConnection.ExecuteNonQuery(command); } catch (Exception ex) { throw ex; } return(Cordenate); }
public CordenatesModel Insert(CordenatesModel Cordenate) { SqlHelper dataConnection; SqlCommand command; try { dataConnection = new SqlHelper(_loggerFactory, _config); command = new SqlCommand($@"INSERT INTO cordenadas ( ID_end ,Latitude ,Longitude ) OUTPUT inserted.ID VALUES ( @ID_end ,@Latitude ,@Longitude )" ); command.Parameters.AddWithValue("ID_end", Cordenate.ID_end.AsDbValue()); command.Parameters.AddWithValue("Latitude", Cordenate.Latitude.AsDbValue()); command.Parameters.AddWithValue("Longitude", Cordenate.Longitude.AsDbValue()); Cordenate.ID = (int)dataConnection.ExecuteScalar(command); } catch (Exception ex) { throw ex; } return(Cordenate); }
public CordenatesModel Update(CordenatesModel cordenates) { CordenatesRepository cordenatesRepository; try { cordenatesRepository = new CordenatesRepository(_loggerFactory, _config); if (cordenates.ID == 0) { throw new Exception("ID diferente de 0, avalie a utilização do POST"); } else { cordenatesRepository.Update(cordenates); } } catch (Exception ex) { throw ex; } return(cordenates); }