public async Task <bool> DeleteAsync(PottyBreak pottyBreak)
        {
            var tableEntity     = pottyBreak.AsDynamicTableEntity();
            var deleteOperation = TableOperation.Delete(tableEntity);
            var tableResult     = await _tableReference.ExecuteAsync(deleteOperation);

            return(tableResult.HttpStatusCode >= 200 && tableResult.HttpStatusCode < 300);
        }
        public async Task <IActionResult> PutPottyBreakAsync([FromBody] PottyBreak pottyBreak)
        {
            //if (!ModelState.IsValid)
            //    return BadRequest(ModelState);

            await _pottyBreaksManager.SaveAsync(pottyBreak);

            return(CreatedAtAction(nameof(GetAsync), pottyBreak));
        }
Esempio n. 3
0
        public async Task DeleteAsync(PottyBreak pottyBreak)
        {
            //TODO: Log this
            if (pottyBreak is null)
            {
                return;
            }

            await _simpleCache.RemoveAsync(pottyBreak, _pottyBreakRepository.DeleteAsync);
        }
Esempio n. 4
0
 public PottyBreakRepositoryTests()
 {
     TestablePottyBreak = new PottyBreak
     {
         Id       = Guid.Parse(TestableGuid),
         DateTime = DateTime.Now,
         Peed     = true,
         Pooed    = false,
         Comment  = "For Testing"
     };
 }
Esempio n. 5
0
        public async Task DeletePottyBreak(PottyBreak pottyBreak)
        {
            var url      = $"{ResourceUrl}/{pottyBreak.Id.ToString()}";
            var response = await HttpClient.DeleteAsync(url);

            if (!response.IsSuccessStatusCode)
            {
                //TODO: Log this too
            }
            else
            {
                Notify?.Invoke(pottyBreak);
            }
        }
Esempio n. 6
0
        public async Task SaveAsync(PottyBreak pottyBreak)
        {
            //TODO: Log?
            if (pottyBreak is null)
            {
                return;
            }

            if (!_dateEntryValidator.IsValid(pottyBreak.DateTime))
            {
                return;
            }

            await _simpleCache.AddAsync(pottyBreak, _pottyBreakRepository.SaveAsync);
        }
Esempio n. 7
0
        public async Task SaveOrUpdatePottyBreak(PottyBreak pottyBreak)
        {
            var json     = JsonConvert.SerializeObject(pottyBreak);
            var content  = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await HttpClient.PostAsync(ResourceUrl, content);

            if (!response.IsSuccessStatusCode)
            {
                //TODO: Let's log this
            }
            else
            {
                Notify?.Invoke(pottyBreak);
            }
        }
        public static DynamicTableEntity AsDynamicTableEntity(this PottyBreak pottyBreak)
        {
            var entity = new DynamicTableEntity
            {
                ETag         = "*",
                PartitionKey = POTTYBREAK_PARTITIONKEY,
                RowKey       = pottyBreak.Id.ToString(),
            };

            entity.Properties.Add("datetime", new EntityProperty(pottyBreak.DateTime));
            entity.Properties.Add("peed", new EntityProperty(pottyBreak.Peed));
            entity.Properties.Add("pooed", new EntityProperty(pottyBreak.Pooed));
            entity.Properties.Add("comment", new EntityProperty(pottyBreak.Comment));

            return(entity);
        }