Example #1
0
        private static async Task <Boolean> isIdInTable(CloudTable table, String colName, string platId)
        {
            TableQuery <PlateNumber> idQuery = new TableQuery <PlateNumber>()
                                               .Where(TableQuery.GenerateFilterCondition(colName, QueryComparisons.Equal, platId));
            TableQuerySegment <PlateNumber> queryResult = await table.ExecuteQuerySegmentedAsync(idQuery, null);

            PlateNumber plateNumber = queryResult.FirstOrDefault();

            if (plateNumber == null)
            {
                return(false);
            }
            ownerName = plateNumber.PartitionKey;
            return(true);
        }
Example #2
0
        private static async Task <String> updatePlateNumber(CloudTable cloudTable, string id, string owner, string action)
        {
            if (action.Equals("add"))
            {
                try
                {
                    PlateNumber newPlate = new PlateNumber();
                    newPlate.PartitionKey = owner;
                    newPlate.RowKey       = id;

                    TableOperation add = TableOperation.InsertOrReplace(newPlate);
                    await cloudTable.ExecuteAsync(add);
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
                return("Success");
                // action=='remove'
            }
            else
            {
                try
                {
                    List <string> list = new List <string>();
                    list.Add(id);
                    TableOperation retrieve = TableOperation.Retrieve <PlateNumber>(owner, id);

                    TableResult result = await cloudTable.ExecuteAsync(retrieve);

                    var deleteEntity = (PlateNumber)result.Result;

                    TableOperation delete = TableOperation.Delete(deleteEntity);

                    await cloudTable.ExecuteAsync(delete);
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
                return("Success");
            }
        }