public IEnumerable <BatteryDTO> FindAll() { string query = "select capacity, idb, power, state, time from batteries"; List <BatteryDTO> batteryList = new List <BatteryDTO>(); using (IDbConnection connection = ConnectionUtil_Pooling.GetConnection()) { connection.Open(); using (IDbCommand command = connection.CreateCommand()) { command.CommandText = query; command.Prepare(); using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { BatteryDTO b = new BatteryDTO(reader.GetDouble(0), reader.GetString(1), reader.GetDouble(2), (Enums.BatteryRezim)Enum.Parse(typeof(Enums.BatteryRezim), reader.GetString(3)), reader.GetInt32(4)); batteryList.Add(b); } } } } return(batteryList); }
public async Task <IActionResult> ChangeBatteryStatus(long id, BatteryDTO batteryDTO) { if (id != batteryDTO.Id) { return(BadRequest()); } var battery = await _context.Batteries.FindAsync(id); if (battery == null) { return(NotFound()); } battery.BatteryStatus = batteryDTO.BatteryStatus; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BatteriesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Save(BatteryDTO entity) { using (IDbConnection connection = ConnectionUtil_Pooling.GetConnection()) { connection.Open(); Save(entity, connection); } }
public void Save(BatteryDTO entity, IDbConnection connection) { String insertSql = "insert into batteries (capacity,power,state,vreme,idb) values (:capacity, :power, :state,:vreme, :idb)"; // String updateSql = "update batteries set capacity=:capacity, power = :power, state = :state, time=:time where idb =:idb"; using (IDbCommand command = connection.CreateCommand()) { // command.CommandText = ExistsById(entity.Id,connection) ? updateSql : insertSql; command.CommandText = insertSql; ParameterUtil.AddParameter(command, "capacity", DbType.Double); ParameterUtil.AddParameter(command, "power", DbType.Double); ParameterUtil.AddParameter(command, "state", DbType.String); ParameterUtil.AddParameter(command, "vreme", DbType.Int32); ParameterUtil.AddParameter(command, "idb", DbType.String); ParameterUtil.SetParameterValue(command, "idb", entity.Id); ParameterUtil.SetParameterValue(command, "vreme", entity.Time); ParameterUtil.SetParameterValue(command, "state", entity.State.ToString()); ParameterUtil.SetParameterValue(command, "power", entity.MaxPower); ParameterUtil.SetParameterValue(command, "capacity", entity.Capacity); command.ExecuteNonQuery(); } }
public IEnumerable <BatteryDTO> FindAllById(string id, int secondsStart, int secondsEnd) { string query = "select capacity, idb, power, state, vreme from batteries " + " where idb =:idb and vreme >=:s and vreme <=:e " + "order by vreme asc"; List <BatteryDTO> batteryList = new List <BatteryDTO>(); using (IDbConnection connection = ConnectionUtil_Pooling.GetConnection()) { connection.Open(); using (IDbCommand command = connection.CreateCommand()) { command.CommandText = query; ParameterUtil.AddParameter(command, "idb", DbType.String); ParameterUtil.AddParameter(command, "s", DbType.Int32); ParameterUtil.AddParameter(command, "e", DbType.Int32); command.Prepare(); ParameterUtil.SetParameterValue(command, "e", secondsEnd); ParameterUtil.SetParameterValue(command, "s", secondsStart); ParameterUtil.SetParameterValue(command, "idb", id); using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { BatteryDTO b = new BatteryDTO(reader.GetDouble(0), reader.GetString(1), reader.GetDouble(2), (Enums.BatteryRezim)Enum.Parse(typeof(Enums.BatteryRezim), reader.GetString(3)), reader.GetInt32(4)); batteryList.Add(b); } } } } return(batteryList); }
public void Delete(BatteryDTO entity) { throw new NotImplementedException(); }