コード例 #1
0
        /// <summary>
        /// This method receives a FermentationLog entity from the servcie and inserts the data into the SQLite DB
        /// </summary>
        /// <param name="log"> The Entity that is received from the service</param>
        /// <returns></returns>
        public async Task AddFermentabuoyLog(FermentabuoyLog log)
        {
            string sql = "Insert into FermentationLog (Name, Batch, Temperature, Gravity, Angle, DeviceId, Battery, RSSI, Created) " +
                         "VALUES (@Name, @Batch, @Temperature, @Gravity, @Angle, @DeviceId, @Battery, @RSSI, @Created);";

            using (IDbConnection db = new SqliteConnection(_configuration.GetConnectionString("SabreSpringsBrewing")))
            {
                await db.ExecuteAsync(sql, log);
            }
        }
コード例 #2
0
        /// <summary>
        /// Retrieves a Log entity from the database
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <FermentabuoyLog> GetLog(int id)
        {
            FermentabuoyLog log = new FermentabuoyLog();
            string          sql = @"Select * from FermentationLog where Id = @Id;";

            using (IDbConnection db = new SqliteConnection(_configuration.GetConnectionString("SabreSpringsBrewing")))
            {
                log = await db.QueryFirstAsync <FermentabuoyLog>(sql, new { Id = id });
            }
            return(log);
        }
コード例 #3
0
 /// <summary>
 /// This method takes the dto from the API controller and translates the data to a 
 /// matching entity which is then given to the data provider to be inserted into the database.
 /// </summary>
 /// <param name="fermentabuoyLogDto"> The Dto received by the controller layer</param>
 /// <returns></returns>
 public async Task AddFermentabuoyLog(FermentabuoyLogDto fermentabuoyLogDto) 
 {
     Log.Information($"Adding new Log with ID:{fermentabuoyLogDto.ID}");
     FermentabuoyAssignment currentAssignment = await FermentabuoyAssignmentDataProvider.GetLatestAssginment(fermentabuoyLogDto.ID);
     FermentabuoyLog log = new FermentabuoyLog()
     {
         Name = fermentabuoyLogDto.Name,
         Batch = currentAssignment.Batch,
         DeviceId = fermentabuoyLogDto.ID,
         Angle = fermentabuoyLogDto.Angle,
         Temperature = fermentabuoyLogDto.Temperature,
         Battery = fermentabuoyLogDto.Battery,
         Gravity = fermentabuoyLogDto.Gravity,
         RSSI = fermentabuoyLogDto.RSSI,
         Created = DateTime.Now
     };
     await FermentabuoyLogDataProvider.AddFermentabuoyLog(log);   
 }
コード例 #4
0
 /// <summary>
 /// Get FermentabuoyLog DTO from ID of an entity
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public async Task<FermentabuoyLogDto> GetLog(int id)
 {
     FermentabuoyLog log = await FermentabuoyLogDataProvider.GetLog(id);
     if(log == null)
     {
         throw new ArgumentException($"Log with ID \"{id}\" was not found.");
     }
     FermentabuoyLogDto logDto = new FermentabuoyLogDto()
     {
         Name = log.Name,
         ID = log.DeviceId,
         Angle = log.Angle,
         Temperature = log.Temperature,
         Battery = log.Battery,
         Gravity = ConvertPlatoToSpecificGravity(log.Gravity),
         RSSI = log.RSSI,
         Created = log.Created.ToString("g")
     };
     return logDto;
 }