public async Task <Uri> CreatePredictionModelAsync(PredictionUsageLightBulbModel lightBulbDbModel)
        {
            var response = await _client.PostAsync("api/LightBulb", new JsonContent(lightBulbDbModel));

            response.EnsureSuccessStatusCode();

            // return URI of the created resource.
            return(response.Headers.Location);
        }
        public async Task SavePredictionModelToDbAsync(int lightBulbID, DateTime dateTime, bool status)
        {
            var predictionUsageLightBulbModel = new PredictionUsageLightBulbModel()
            {
                LightBulbID = lightBulbID, IsOn = status ? 1:0,
                Day         = (int)dateTime.DayOfWeek, Month = dateTime.Month, Time = (dateTime.Hour * 60 + dateTime.Minute)
            };
            var httpClient = new PredictionScheduleApiClient();

            await httpClient.CreatePredictionModelAsync(predictionUsageLightBulbModel);
        }
        public async Task <bool> Update(PredictionUsageLightBulbModel lightBulbDbModel)
        {
            ReplaceOneResult updateResult =
                await _context
                .LightBulbDBModel
                .ReplaceOneAsync(
                    filter : g => g.Id == lightBulbDbModel.Id,
                    replacement : lightBulbDbModel);

            return(updateResult.IsAcknowledged &&
                   updateResult.ModifiedCount > 0);
        }
예제 #4
0
        public async Task <IActionResult> Post([FromBody] PredictionUsageLightBulbModel lightBulbDbModel)
        {
            await _lightBulbRepository.Create(lightBulbDbModel);

            return(new OkObjectResult(lightBulbDbModel));
        }
 public async Task Create(PredictionUsageLightBulbModel lightBulbDbModel)
 {
     await _context.LightBulbDBModel.InsertOneAsync(lightBulbDbModel);
 }