Likes

Developing Windows Azure and Web Services Lab @ 3 Ans 1

Implement the functionality to query the source and destination information of a specific flight by providing the flight number. Start by creating a new Console application project, and use WhereQ extension method of LINQto Entities.



To implement the required functionality, you need to perform the following steps:
1. Browse to the location where you have saved the Exercise 03.zip file.
2. Extract the files.
3. Double-click the Exercise 03 folder.
4. Double-click the BlueYonder.Companion folder.
5. Double-click the BlueYonder.Companion.sin file. The BlueYonder.Companion - Microsoft Visual Studio window displayed.
6. Select FILE—Add—New Project The Add New Project window is displayed.
7. Ensure that the Installed—Visual C# nodes are expanded in the left pane.
8. Select the Windows node in the left pane.
9. Select the Console Application template in the middle pane.
10. Ensure that the framework selected for the project is .NET Framework 4.5
11. Select and replace the existing text in the Name text box with BlueYonder.FlightDetails
12. Click the OK button. The Program.es file is displayed.
13. Ensure that the Solution Explorer window is opened.
14. Right-click the BlueYonder.FlightDetails node, and then select Add Reference The Reference Manager -BlueYonder.FlightDetails dialog box is displayed.
15. Ensure that the Assemblies node is expanded in the left pane.
16. Ensure that the Framework option is selected in the left pane.
17. Type System.Data.Entity in the Search Assemblies combo box.
18. Select the System.Data.Entity option under the Name column in the middle pane.
19. Select the System.Data.Entity check box.
20. Select the Solution node in the left pane.
21. Select the BlueYonder.Entities option under the Name column in the middle pane.
22. Select the BlueYonder.Entities check box.
23. Click the OK button.
24 Right-click the BlueYonder.FlightDetails node, and then select Manage NuGet Packages The BlueYonder.FlightDetails - Manage NuGet Packages dialog box is displayed.
25. Type EntityFramework in the Search Online combo box.
26. Select the EntityFramework option in the middle pane.
27. Click the Install button. The Installing dialog box is displayed for few seconds and closed automatically.
28 Click the Close button to close BlueYonder.FlightDetails - Manage NuGet Packages dialog box.
29. Right-click the BlueYonder.FlightDetails node in the Solution Explorer window, and then select Set as Startup Project
30. Right-click the BlueYonder.FlightDetails node, and then select Add—Class The Add New Item -BlueYonder.FlightDetails dialog box is displayed.
31. Select and replace the existing text in the Name text box with BlueYonderDbContext
32. Click the Add button. The BlueYonderDbContext.es file is displayed.
33. Type the highlighted portions of the following code snippet in the BlueYonderDbContext.es file:
using System;
using System.Collections.Generic;
using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Data.Entity;
 using BlueYonder.Entities;

34. Type the highlighted portions of the following code snippet in the BlueYonderDbContext.es file:
class BlueYonderDbContext: DbContext
{
public BlueYonderDbContext()
 : base(@"Data
Source= Asqlexpress;Database=BlueYonder .Companion.Lab02integrated Security=True;")
{
}
public DbSet<Location> Locations { get; set; }
public DbSet<Flight> Flights { get; set; }
public DbSet<FlightSchedule> FlightSchedules { get; set; }
public DbSet<Traveler> Travelers { get; set; }
public DbSet<Reservation> Reservations { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<FlightSchedule>()
.HasRequired(fs => fs.Flight)
.WithMany(f => f.Schedules)
.Map(m => m.MapKeyC'FlightlD")); modelBuilder.Entity<Reservation>()
.HasRequired(r => r.DepartureFlight)
.WithManyQ
.HasForeignKey(r => r.DepartFlightSchedulelD); modelBuilder.Entity<Reservation>()
.HasOptional(r => r.ReturnFlight)
.WithManyQ
.HasForeignKey(r => r.ReturnFlightSchedulelD);
}
}
35. Ensure that the Solution Explorer window is opened
36. Double-click the Program.es file.
37. Type the highlighted portions of the following code snippet in the Program.es file:
static void Main(string[] args)
{
BlueYonderDbContext bdbc = new BlueYonderObContext() ;
 Console.WriteLine("Please enter the Flight Number:");
 string flightNumber = Console.ReadLine();
var flightDetails = bdbc.Flights.Where(f => f.FlightNumber == flightNumber) .FirstOrDefault();
if (flightDetails != null)
{
Console.WriteLine("The flight starts from " + flightDetails.Source.Ci ”, " + flightDetails.Source.Country + " for " + flightDetails.Destination.City + ", " flightDetails.Destination.Country + ".");
}
else
{
Console.WriteLine("Invalid Flight Number.");
}
Console.WriteLine("\nPress the ENTER key to close the application.") Console. ReadLineQ;
}
38. Select FILE—Save All to save the changes.
39. Press the F5 key to run the application. The Console window is displayed.
40. Type BY001 in the Console window, and then press the Enter key. The flight details is displayed.
41. Press the Enter key to close the application.
42. Close Microsoft Visual Studio 2012.
Console.WriteLine("Invalid Flight Number.");
}

No comments: