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
14 changes: 14 additions & 0 deletions flight-planner.services/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"/>
</configSections>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>
113 changes: 113 additions & 0 deletions flight-planner.services/FlightService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using flight_planner.data;
using flight_planner.Models;

namespace flight_planner.services
{
public class FlightService
{
private static readonly object ListLock = new object();

public async Task<ICollection<Flight>> GetFlights()
{

using (var context = new FlightPlannerDbContext())
{
return await context.Flights.Include(f => f.To).Include(f => f.From).ToListAsync();
}
}

public ServiceResult AddFlight(Flight flight)
{
using (var context = new FlightPlannerDbContext())
{
if (Exists(flight))
{
return new ServiceResult(false);
}
else
{
flight = context.Flights.Add(flight);
context.SaveChanges();
return new ServiceResult(flight.Id, true);
}
}
}

public bool Exists(Flight flight)
{
using (var context = new FlightPlannerDbContext())
{
var exist = context.Flights.Any(f =>
f.Carrier == flight.Carrier && f.ArrivalTime == flight.ArrivalTime &&
f.DepartureTime == flight.DepartureTime &&
f.From.City == flight.From.City &&
f.From.Country == flight.From.Country &&
f.To.AirportCode == flight.To.AirportCode &&
f.To.City == flight.To.City &&
f.To.Country == flight.To.Country &&
f.From.AirportCode == flight.From.AirportCode);


return exist;
}
}


public async Task<ICollection<Airport>> SearchAirports(string search)
{
search = search.ToLowerInvariant().Trim();
using (var context = new FlightPlannerDbContext())
{
var query = context.Airports.Where(a =>
a.City.ToLower().Contains(search) || a.Country.ToLower().Contains(search)
|| a.AirportCode.ToLower().Contains(search));
return await query.ToListAsync();
}
}

public async Task<Flight> GetFlightById(int id)
{
using (var context = new FlightPlannerDbContext())
{
var flight = await context.Flights.Include(f => f.To).Include(f => f.From)
.SingleOrDefaultAsync(f => f.Id == id);

return flight;
}
}


public async Task DeleteFlights()
{
using (var context = new FlightPlannerDbContext())
{
context.Flights.RemoveRange(context.Flights);
context.Airports.RemoveRange(context.Airports);
await context.SaveChangesAsync();
}
}

public async Task RemoveFlightsById(int id)
{
using (var context = new FlightPlannerDbContext())
{

var flight = await context.Flights.SingleOrDefaultAsync(f => f.Id == id);

if (flight != null)
{
context.Flights.Remove(flight);
await context.SaveChangesAsync();
}

}
}

}
}
36 changes: 36 additions & 0 deletions flight-planner.services/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("flight-planner.services")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("flight-planner.services")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("dd361945-c6c6-4f71-8ec7-62a575044db2")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
25 changes: 25 additions & 0 deletions flight-planner.services/ServiceResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace flight_planner.services
{
public class ServiceResult
{
public ServiceResult(int id, bool succeeded)
{
Id = id;
Succeeded = succeeded;
}

public ServiceResult(bool succeeded)
{
Succeeded = succeeded;
}

public int Id { get; }
public bool Succeeded { get; }
}
}
81 changes: 81 additions & 0 deletions flight-planner.services/flight-planner.services.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\EntityFramework.6.3.0\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DD361945-C6C6-4F71-8EC7-62A575044DB2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>flight_planner.services</RootNamespace>
<AssemblyName>flight-planner.services</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.3.0\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.3.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FlightService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServiceResult.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\flight_planner.core\flight_planner.core.csproj">
<Project>{93ac69dc-31d4-4c35-b099-c5e63b752b1c}</Project>
<Name>flight_planner.core</Name>
</ProjectReference>
<ProjectReference Include="..\flight_planner.data\flight_planner.data.csproj">
<Project>{983f2dff-66b5-4fd5-8e48-5e56ab3f10fc}</Project>
<Name>flight_planner.data</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.3.0\build\EntityFramework.props'))" />
<Error Condition="!Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.3.0\build\EntityFramework.targets'))" />
</Target>
<Import Project="..\packages\EntityFramework.6.3.0\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.targets')" />
</Project>
4 changes: 4 additions & 0 deletions flight-planner.services/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.3.0" targetFramework="net472" />
</packages>
18 changes: 18 additions & 0 deletions flight-planner.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ VisualStudioVersion = 16.0.29230.47
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "flight-planner", "flight-planner\flight-planner.csproj", "{1CF60D3B-4877-4F1F-BA03-B4AB44C823E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "flight_planner.data", "flight_planner.data\flight_planner.data.csproj", "{983F2DFF-66B5-4FD5-8E48-5E56AB3F10FC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "flight_planner.core", "flight_planner.core\flight_planner.core.csproj", "{93AC69DC-31D4-4C35-B099-C5E63B752B1C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "flight-planner.services", "flight-planner.services\flight-planner.services.csproj", "{DD361945-C6C6-4F71-8EC7-62A575044DB2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +21,18 @@ Global
{1CF60D3B-4877-4F1F-BA03-B4AB44C823E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1CF60D3B-4877-4F1F-BA03-B4AB44C823E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1CF60D3B-4877-4F1F-BA03-B4AB44C823E8}.Release|Any CPU.Build.0 = Release|Any CPU
{983F2DFF-66B5-4FD5-8E48-5E56AB3F10FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{983F2DFF-66B5-4FD5-8E48-5E56AB3F10FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{983F2DFF-66B5-4FD5-8E48-5E56AB3F10FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{983F2DFF-66B5-4FD5-8E48-5E56AB3F10FC}.Release|Any CPU.Build.0 = Release|Any CPU
{93AC69DC-31D4-4C35-B099-C5E63B752B1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93AC69DC-31D4-4C35-B099-C5E63B752B1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93AC69DC-31D4-4C35-B099-C5E63B752B1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93AC69DC-31D4-4C35-B099-C5E63B752B1C}.Release|Any CPU.Build.0 = Release|Any CPU
{DD361945-C6C6-4F71-8EC7-62A575044DB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD361945-C6C6-4F71-8EC7-62A575044DB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD361945-C6C6-4F71-8EC7-62A575044DB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD361945-C6C6-4F71-8EC7-62A575044DB2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading