public void Add(Pitstop entity) { if (amazingRacecontext != null && amazingRacecontext.Pitstops != null) { if (entity.Id == Guid.Empty) { entity.Id = Guid.NewGuid(); } amazingRacecontext.Pitstops.Add(entity); amazingRacecontext.SaveChanges(); } }
private static async Task UpdateDocumentLargeImageUrl(string documentId, string largeImageUrl) { string endpointUri = "https://oursitename.documents.azure.com:443/"; string key = "AnotherSecretYouCannotSee=="; string databaseName = "JourneyNotesDB"; string collectionName = "Pitstop"; // using Microsoft.Azure.DocumentDB.Core library DocumentClient documentClient = new DocumentClient(new Uri(endpointUri), key); // Finding and updating the trip that needs to be updated with the new image: var documentUri = UriFactory.CreateDocumentUri(databaseName, collectionName, documentId); Pitstop pitstop = await documentClient.ReadDocumentAsync <Pitstop>(documentUri); pitstop.PhotoLargeUrl = largeImageUrl; await documentClient.ReplaceDocumentAsync(documentUri, pitstop); }
public void Update(Pitstop pitstopToUpdate) { amazingRacecontext.Entry(pitstopToUpdate).State = EntityState.Modified; amazingRacecontext.SaveChanges(); }
public async Task <ActionResult <string> > GetTripAndPitstops(int Id) { string UserID = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value; //string UserID = "666"; var tripList = new List <TripTableEntity>(); 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) { if (entity.TripId == Id) { tripList.Add(entity); } } } while (tokenTrip != null); var tripDetails = tripList.FirstOrDefault(); if (tripDetails == null) { return(NotFound()); } //Get pitstops List <Pitstop> pitstopList = new List <Pitstop>(); TableQuery <PitstopTableEntity> queryPitstop = new TableQuery <PitstopTableEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, Id.ToString() + ";" + UserID)); TableContinuationToken tokenPitstop = null; do { TableQuerySegment <PitstopTableEntity> resultSegment = await _tablePitstop.ExecuteQuerySegmentedAsync(queryPitstop, tokenPitstop); tokenPitstop = resultSegment.ContinuationToken; foreach (PitstopTableEntity entity in resultSegment.Results) { Pitstop pitstop = new Pitstop(entity); pitstopList.Add(pitstop); } } while (tokenPitstop != null); Trip trip = new Trip { TripId = tripDetails.TripId, Description = tripDetails.Description, EndDate = tripDetails.EndDate, Headline = tripDetails.Headline, MainPhotoSmallUrl = tripDetails.MainPhotoSmallUrl, MainPhotoUrl = tripDetails.MainPhotoUrl, PersonId = tripDetails.PersonId, Pitstops = pitstopList, Position = tripDetails.Position, StartDate = tripDetails.StartDate }; return(Ok(trip)); }
private async Task ProcessPitstops() { int colRaceId = 0; int coldriverId = 1; int colLapnr = 2; int colMil = 6; string filename = @"D:\git\blazoring\pit_stops.csv"; using (StreamReader reader = new StreamReader(filename)) { //eerste regel is zooi await reader.ReadLineAsync(); // key: driverId uit geval, driverEntryId // dus: als we in het bestand een driverId vinden. // gaan we naar _drivers[driverId] om DRIVERID database te krijgen // met dat nummer zoeken we in de database naar het DriverEntryId dat bij deze rijder en dit event hoort // dat nummer stoppen in de de entries database. // daarna, als een op een regel dus een DriverId tegenkomen, weten we het juiste driverentryid nummer // man, man, man. var entries = new Dictionary <int, int>(); int currentRaceId = -1; int counter = 1; //eerste regel is zooi await reader.ReadLineAsync(); while (!reader.EndOfStream) { var line = await reader.ReadLineAsync(); var splitted = Split(line); int raceId = Convert.ToInt32(splitted[colRaceId]); int driverId = Convert.ToInt32(splitted[coldriverId]); int lap = Convert.ToInt32(splitted[colLapnr]); int milli = Convert.ToInt32(splitted[colMil]); if (raceId != currentRaceId) { Console.WriteLine($"New race!: {raceId}"); var convertedRaceId = _raceEvents[raceId].RaceEventId; currentRaceId = raceId; var entriesTemp = await _context.EventResults .AsNoTracking() .Include(er => er.DriverEntry) .AsNoTracking() .Where(er => er.RaceEventId == convertedRaceId) .Select(x => x.DriverEntry) .ToListAsync(); entries = new Dictionary <int, int>(); foreach (var et in entriesTemp) { var mappedDriverId = _drivers[et.DriverId]; entries.Add(mappedDriverId, et.DriverEntryId); } } var raceEvent = _raceEvents[raceId].RaceEventId; if (!entries.ContainsKey(driverId)) { Console.WriteLine("possible race not run!"); counter++; continue; } var driverToUse = entries[driverId]; var pitstop = new Pitstop { RaceEventId = raceEvent, DriverEntryId = driverToUse, LapNumber = lap, Milliseconds = milli }; Console.WriteLine($"adding lap nr {counter}: {milli}ms"); _context.Pitstops.Add(pitstop); //elke 1000 committen //if (counter % 1000 == 0) //{ //await _context.SaveChangesAsync(); //} counter++; } } await _context.SaveChangesAsync(); }
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()); }