Ejemplo n.º 1
0
        //Non-action
        private static async Task <string> RemoveTripImagesFromBlob(TripTableEntity trip, CloudBlobContainer container)
        {
            string         smallImageName = trip.MainPhotoSmallUrl;
            string         largeImageName = trip.MainPhotoUrl;
            CloudBlockBlob smallImage     = container.GetBlockBlobReference(smallImageName);
            CloudBlockBlob largeImage     = container.GetBlockBlobReference(largeImageName);

            using (var deleteStream = await smallImage.OpenReadAsync()) { }
            await smallImage.DeleteIfExistsAsync();

            using (var deleteStream = await largeImage.OpenReadAsync()) { }
            await largeImage.DeleteIfExistsAsync();

            return($"Deleted images {smallImageName} and {largeImageName}");
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <string> > PostNewTrip(NewTrip newTrip)
        {
            string UserID = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
            //string UserID = "666";

            //if (!ModelState.IsValid)
            //{
            //    return BadRequest("Something wrong with the trip details.");
            //}

            Trip trip = new Trip();

            var tripList = new List <TripTableEntity>();

            string photoName = await StorePicture(newTrip.picture);

            // Determining the tripId number
            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);

            var tripCount = 0;

            if (tripList.Count() != 0)
            {
                tripCount = tripList.Max(a => a.TripId);
            }

            trip.TripId      = tripCount + 1;
            trip.PersonId    = UserID;
            trip.Headline    = newTrip.Headline;
            trip.Description = newTrip.Description;
            trip.StartDate   = newTrip.StartDate;
            trip.EndDate     = newTrip.EndDate;
            if (trip.EndDate.Year.Equals(0001))
            {
                trip.EndDate = trip.StartDate;
            }
            trip.Position          = newTrip.Position;
            trip.MainPhotoUrl      = photoName; // this needs to be updated! And the picture will be deleted at some point - we will not store huge pics.
            trip.MainPhotoSmallUrl = string.Empty;

            TripTableEntity tripTable = new TripTableEntity(trip);

            TableOperation insertOperation = TableOperation.Insert(tripTable);

            await _tableTrip.ExecuteAsync(insertOperation);


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

            return(Ok($"Trip created, id: {trip.TripId}"));
        }