public async Task AddFermentabuoyAssignment(FermentabuoyAssignment assignment)
        {
            string sql = "Insert into FermentabuoyAssignment (Fermentabuoy, Batch, CreatedBy, Created) " +
                         "VALUES (@Fermentabuoy, @Batch, @CreatedBy, @Created);";

            using (IDbConnection db = new SqliteConnection(_configuration.GetConnectionString("SabreSpringsBrewing")))
            {
                await db.ExecuteAsync(sql, assignment);
            }
        }
 public async Task AddFermentabuoyAssignment(FermentabuoyAssignmentDto dto)
 {
     FermentabuoyAssignment entity = new FermentabuoyAssignment()
     {
         Fermentabuoy = dto.Fermentabuoy,
         Batch        = dto.Batch,
         CreatedBy    = dto.CreatedBy,
         Created      = DateTime.Now
     };
     await FermentabuoyAssigmentDataProvider.AddFermentabuoyAssignment(entity);
 }
        public async Task <List <FermentabuoyAssignment> > GetAllAssignments()
        {
            FermentabuoyAssignment assignment = new FermentabuoyAssignment();
            string sql = @"Select * from FermentabuoyAssignment assign join Fermentabuoy buoy on assign.Fermentabuoy = buoy.Id where buoy.DeviceId = @DeviceId order  by Created desc;";

            using (IDbConnection db = new SqliteConnection(_configuration.GetConnectionString("SabreSpringsBrewing")))
            {
                var queryResults = await db.QueryAsync <FermentabuoyAssignment>(sql);

                return(queryResults.ToList());
            }
        }
Ejemplo n.º 4
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);   
 }
        /// <summary>
        /// Searches database for the the latest created assignment
        /// for this fermentabuoy
        /// </summary>
        /// <param name="fermentabuoyId"></param>
        /// <returns></returns>
        public async Task <FermentabuoyAssignment> GetLatestAssginment(int deviceId)
        {
            FermentabuoyAssignment assignment = new FermentabuoyAssignment();
            string sql = @"Select * from FermentabuoyAssignment assign join Fermentabuoy buoy on assign.Fermentabuoy = buoy.Id where buoy.DeviceId = @DeviceId order  by Created desc;";

            using (IDbConnection db = new SqliteConnection(_configuration.GetConnectionString("SabreSpringsBrewing")))
            {
                var queryResults = await db.QueryAsync <FermentabuoyAssignment>(sql, new { DeviceId = deviceId });

                if (queryResults.Any() == false)
                {
                    throw new InvalidOperationException($"Fermentabuoy {deviceId} does not have an assignment");
                }
                else
                {
                    assignment = queryResults.First();
                }
            }

            return(assignment);
        }