public static List <TripModel> CreateNewTrip() { AddTrip addTrip = new AddTrip(); addTrip.ShowDialog(); if (addTrip.DialogResult == true) { if (NewTrip.Count == 1) { SaveNewTrip(NewTrip[0]); List <TripModel> trip = new List <TripModel>(NewTrip); NewTrip.Clear(); return(trip); } else if (NewTrip.Count == 2) { NewTrip.ForEach(nt => SaveNewTrip(nt)); List <TripModel> trip = new List <TripModel>(NewTrip); NewTrip.Clear(); return(trip); } else { return(null); } } else { return(null); } }
public IHttpActionResult GetTripCost(NewTrip newTrip) { var PriceMatrix = _context.PriceMatrices .Where(p => p.EntryStationid == newTrip.EntryPointId && p.ExitStationid == newTrip.ExitPointId) .ToList(); if (PriceMatrix == null) { return(NotFound()); } return(Ok(PriceMatrix)); }
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}")); }