public async Task <ActionResult <string> > PostPitstop(NewPitstop newPitstop)
        {
            string UserID = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
            //string UserID = "666";

            List <Pitstop> pitstopList = new List <Pitstop>();

            var tripList = new List <TripTableEntity>();

            //TripEntity from trip table
            var tripQuery = new TableQuery <TripTableEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, UserID));
            TableContinuationToken tokenTrip = null;

            do
            {
                TableQuerySegment <TripTableEntity> resultSegment = await _tableTrip.ExecuteQuerySegmentedAsync(tripQuery, tokenTrip);

                tokenTrip = resultSegment.ContinuationToken;

                foreach (TripTableEntity entity in resultSegment.Results)
                {
                    tripList.Add(entity);
                }
            } while (tokenTrip != null);

            //Get pitstops
            List <PitstopTableEntity> pitstopList2 = new List <PitstopTableEntity>();

            TableQuery <PitstopTableEntity> pitstopQuery = new TableQuery <PitstopTableEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, newPitstop.TripId.ToString() + ";" + UserID));

            TableContinuationToken tokenPitstop = null;

            do
            {
                TableQuerySegment <PitstopTableEntity> resultSegment = await _tablePitstop.ExecuteQuerySegmentedAsync(pitstopQuery, tokenPitstop);

                tokenPitstop = resultSegment.ContinuationToken;

                foreach (PitstopTableEntity entity in resultSegment.Results)
                {
                    pitstopList2.Add(entity);
                }
            } while (tokenPitstop != null);

            //Check if trip exists in trip table (if not return not found)
            if (tripList.Where(a => a.TripId == newPitstop.TripId).Count() != 0)
            {
                var nextPitsop = 1;

                if (pitstopList2.Count != 0)
                {
                    nextPitsop = pitstopList2.Select(a => a.PitstopId).Max() + 1;
                }

                string photoName = await StorePicture(newPitstop.picture);

                Pitstop pitstop = new Pitstop();

                pitstop.PersonId    = UserID;
                pitstop.PitstopId   = nextPitsop;
                pitstop.Title       = newPitstop.Title;
                pitstop.Note        = newPitstop.Note;
                pitstop.PitstopDate = newPitstop.PitstopDate;
                if (pitstop.PitstopDate.Year.Equals(0001))
                {
                    pitstop.PitstopDate = DateTime.Now;
                }
                pitstop.PhotoLargeUrl   = photoName;    // will be replaced with the url to the resized image.
                pitstop.PhotoMediumUrl  = string.Empty; // will be updated when the image has been resized.
                pitstop.PhotoSmallUrl   = string.Empty; // will be updated when the image has been resized.
                pitstop.TripId          = newPitstop.TripId;
                pitstop.pitstopPosition = newPitstop.pitstopPosition;
                pitstop.Address         = newPitstop.Address;

                PitstopTableEntity pitstopTable = new PitstopTableEntity(pitstop);

                TableOperation insertOperation = TableOperation.Insert(pitstopTable);

                await _tablePitstop.ExecuteAsync(insertOperation);

                await AddQueueItem(new QueueParam { PartitionKey = pitstopTable.PartitionKey, RowKey = pitstopTable.RowKey, PictureUri = photoName });

                return(Ok($"Pitstop created under trip {pitstop.TripId}, id: {pitstop.PitstopId}"));
            }
            return(NotFound());
        }
        public async Task <ActionResult <string> > PutPitstop([FromRoute] int TripId, [FromRoute] int PitstopId, [FromBody] NewPitstop updatedPitstop)
        {
            string UserID = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
            //string UserID = "666";

            var pitstopList = new List <PitstopTableEntity>();

            var pitstopQuery = new TableQuery <PitstopTableEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, TripId.ToString() + ";" + UserID));
            TableContinuationToken tokenPitstop = null;

            do
            {
                TableQuerySegment <PitstopTableEntity> resultSegment = await _tablePitstop.ExecuteQuerySegmentedAsync(pitstopQuery, tokenPitstop);

                tokenPitstop = resultSegment.ContinuationToken;

                foreach (PitstopTableEntity entity in resultSegment.Results)
                {
                    if (entity.PitstopId == PitstopId)
                    {
                        pitstopList.Add(entity);
                    }
                }
            } while (tokenPitstop != null);

            var pitstop = pitstopList.FirstOrDefault();

            //not working...
            if (pitstop != null)
            {
                pitstop.Title           = updatedPitstop.Title;
                pitstop.Note            = updatedPitstop.Note;
                pitstop.PitstopDate     = updatedPitstop.PitstopDate;
                pitstop.pitstopPosition = updatedPitstop.pitstopPosition;
                pitstop.Address         = updatedPitstop.Address;

                TableOperation replaceOperation = TableOperation.Replace(pitstop);

                await _tablePitstop.ExecuteAsync(replaceOperation);

                return(Ok(pitstop));
            }
            return(NotFound());
        }