Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Advanced-Topics-in-C-Sharp/Advanced-Topics-in-C-Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

Expand Down
14 changes: 14 additions & 0 deletions Advanced-Topics-in-C-Sharp_Lab03/Models/Direction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Advanced_Topics_in_C_Sharp_Lab03.Models
{
public enum Direction
{
North,
South,
East,
West,
Northeast,
Northwest,
Southeast,
Southwest
}
}
20 changes: 20 additions & 0 deletions Advanced-Topics-in-C-Sharp_Lab03/Models/Route.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Advanced_Topics_in_C_Sharp_Lab03.Models
{
public class Route
{
public int Number { get; set; }
public string Name { get; set; }
public Direction Direction { get; set; }
public bool RampAccessible { get; set; }
public bool BicycleAccessible { get; set; }
public Route(int number, string name, Direction direction, bool rampAccessible, bool bicycleAccessible)
{
Number = number;
Name = name;
Direction = direction;
RampAccessible = rampAccessible;
BicycleAccessible = bicycleAccessible;

}
}
}
17 changes: 17 additions & 0 deletions Advanced-Topics-in-C-Sharp_Lab03/Models/ScheduledStop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Advanced_Topics_in_C_Sharp_Lab03.Models
{
public class ScheduledStop
{
public int Id { get; set; }
public Stop Stop { get; set; }
public Route Route { get; set; }
public DateTime ScheduledArrival { get; set; }
public ScheduledStop(int id, Stop stop, Route route, DateTime scheduledArrival)
{
Id = id;
Stop = stop;
Route = route;
ScheduledArrival = scheduledArrival;
}
}
}
18 changes: 18 additions & 0 deletions Advanced-Topics-in-C-Sharp_Lab03/Models/Stop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Advanced_Topics_in_C_Sharp_Lab03.Models
{
public class Stop
{
public int Number { get; set; }
public string Street { get; set; }
public string Name { get; set; }
public Direction Direction { get; set; }
public Stop(int number, string street, string name, Direction direction)
{
Number = number;
Street = street;
Name = name;
Direction = direction;

}
}
}
119 changes: 92 additions & 27 deletions Advanced-Topics-in-C-Sharp_Lab03/Program.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,106 @@
using Advanced_Topics_in_C_Sharp_Lab03.Models;
using Route = Advanced_Topics_in_C_Sharp_Lab03.Models.Route;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
List<Route> routes = new List<Route>();

List<Stop> stops = new List<Stop>();

List<ScheduledStop> scheduledStops = new List<ScheduledStop>();

Route routeOne = new Route(1, "streetOne", Direction.North, true, false);
Route routeTwo = new Route(2, "streetTwo", Direction.East, true, true);
routes.Add(routeOne);
routes.Add(routeTwo);

Stop stopOne = new Stop(1, "streetOne", "firstStop", Direction.South);
Stop stopTwo = new Stop(2, "streetOne", "secondStop", Direction.West);
Stop stopThree = new Stop(3, "streetOne", "thirdStop", Direction.Southeast);
Stop stopFour = new Stop(4, "streetTwo", "forthStop", Direction.North);
Stop stopFive = new Stop(5, "streetTwo", "fifthStop", Direction.Southwest);

stops.Add(stopOne);
stops.Add(stopTwo);
stops.Add(stopThree);
stops.Add(stopFour);
stops.Add(stopFive);

ScheduledStop scheduledStopOne = new ScheduledStop(1, stopOne, routeOne, DateTime.Now);
ScheduledStop scheduledStopTwo = new ScheduledStop(2, stopTwo, routeOne, DateTime.Now.AddMinutes(10));
ScheduledStop scheduledStopThree = new ScheduledStop(3, stopThree, routeOne, DateTime.Now.AddMinutes(20));
ScheduledStop scheduledStopFour = new ScheduledStop(4, stopFour, routeOne, DateTime.Now.AddMinutes(30));
ScheduledStop scheduledStopFive = new ScheduledStop(5, stopFive, routeOne, DateTime.Now.AddMinutes(40));

ScheduledStop scheduledStopSix = new ScheduledStop(6, stopFive, routeTwo, DateTime.Now);
ScheduledStop scheduledStopSeven = new ScheduledStop(7, stopFour, routeTwo, DateTime.Now.AddMinutes(10));
ScheduledStop scheduledStopEight = new ScheduledStop(8, stopThree, routeTwo, DateTime.Now.AddMinutes(20));
ScheduledStop scheduledStopNine = new ScheduledStop(9, stopTwo, routeTwo, DateTime.Now.AddMinutes(30));
ScheduledStop scheduledStopTen = new ScheduledStop(10, stopOne, routeTwo, DateTime.Now.AddMinutes(40));

scheduledStops.Add(scheduledStopOne);
scheduledStops.Add(scheduledStopTwo);
scheduledStops.Add(scheduledStopThree);
scheduledStops.Add(scheduledStopFour);
scheduledStops.Add(scheduledStopFive);
scheduledStops.Add(scheduledStopSix);
scheduledStops.Add(scheduledStopSeven);
scheduledStops.Add(scheduledStopEight);
scheduledStops.Add(scheduledStopNine);
scheduledStops.Add(scheduledStopTen);


app.MapGet("/routes", () =>
{
return routes;
});

IEnumerable<ScheduledStop> GetScheduledStopsByRoute(Route route)
{
app.UseSwagger();
app.UseSwaggerUI();
return scheduledStops.Where(s => s.Route == route).OrderBy(a => a.ScheduledArrival);
}

var summaries = new[]
app.MapGet("/routes/{number}", (int number) =>
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
Route route = routes.FirstOrDefault(a => a.Number == number);

List<ScheduledStop> scheduledStops = GetScheduledStopsByRoute(route).Take(5).ToList();

return Results.Ok(new
{
Route = route,
ScheduledStops = scheduledStops
});

});

app.MapGet("/weatherforecast", () =>
app.MapGet("/stops/{number}", (int number) =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateTime.Now.AddDays(index),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
})
.WithName("GetWeatherForecast");

app.Run();

internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary)
Stop stop = stops.FirstOrDefault(s => s.Number == number);

return Results.Ok(stop);
});

app.MapGet("/stop/{number}/schedule", (int number, int top) =>
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
Stop stop = stops.FirstOrDefault(a => a.Number == number);
if (stop == null)
{
return Results.NotFound();
}

List<ScheduledStop> scheduleds = scheduledStops.Where(b => b.Stop.Number == number)
.OrderBy(c => c.ScheduledArrival)
.Take(top)
.ToList();

return Results.Ok(scheduleds);
});

app.Run();