public IActionResult Update(TripUpdate model) { if (!ModelState.IsValid) { return(BadRequest()); } _tripService.Update(model, User.Claims); return(Ok()); }
static void Main(string[] args) { DateTime phDate = DateTime.UtcNow.AddHours(8); List <RTTripUpdates> tripUpdates = db.Database .SqlQuery <RTTripUpdates>("RTTripUpdatesGetActive @travel_date" , new SqlParameter("@travel_date", phDate.ToString("yyyyMMdd"))) .ToList(); FeedMessage feed = new FeedMessage(); if (tripUpdates.Count > 0) { foreach (RTTripUpdates tripUpdate in tripUpdates) { TripDescriptor td = new TripDescriptor(); td.TripId = tripUpdate.trip_id; td.RouteId = tripUpdate.route_id; td.DirectionId = (uint)tripUpdate.direction_id; td.StartDate = tripUpdate.start_date; td.StartTime = tripUpdate.start_time; TripUpdate tp = new TripUpdate(); tp.Delay = tripUpdate.delay; tp.Trip = td; FeedEntity entity = new FeedEntity(); entity.TripUpdate = tp; entity.Id = tripUpdate.id.ToString(); feed.Entities.Add(entity); } byte[] objSerialized = Functions.ProtoSerialize(feed); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); string filename = "tripupdate.pb"; // Create a CloudFileClient object for credentialed access to Azure Files. CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); // Get a reference to the file share we created previously. CloudFileShare share = fileClient.GetShareReference("gtfsrt"); share.CreateIfNotExists(); var rootDir = share.GetRootDirectoryReference(); using (var stream = new MemoryStream(objSerialized, writable: false)) { rootDir.GetFileReference(filename).UploadFromStream(stream);//.UploadFromByteArray(feed,); } } // Functions.CreatePBFile(storageAccount, filename, objSerialized); }
private static async Task SendNextMessageAsync(TripUpdate currentUpdate) { TripUpdateData rawData = currentUpdate.data; // This is what gets sent to iot hub (I hope) string raw = JsonConvert.SerializeObject(rawData); raw = "{\"Parameters\":" + "\"" + raw.Replace("\"", "\\\"") + "\"" + "}"; var message = new Message(Encoding.ASCII.GetBytes(raw)); // Send the tlemetry message await s_deviceClient.SendEventAsync(message); Console.WriteLine("Message Sent...hopefully"); }
public void Update(TripUpdate model, IEnumerable <Claim> claims) { var entity = _dbContext.Trips.SingleOrDefault(m => m.Id == model.Id); if (entity == null) { throw new NotFoundException(nameof(Trip), model.Id); } if (!_authorizationService.AllowModifyEntity(claims, entity.UserId)) { throw new NotAuthorizedException(); } entity.Price = model.Price; entity.Country = model.Country; entity.DateEnd = model.DateEnd; entity.DateStart = model.DateStart; _dbContext.Trips.Update(entity); _dbContext.SaveChanges(); }