Add project files.
This commit is contained in:
parent
4f7084462b
commit
a758d855a7
23
MovieDB/App.config
Normal file
23
MovieDB/App.config
Normal file
@ -0,0 +1,23 @@
|
||||
<?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>
|
||||
<connectionStrings>
|
||||
<add name="MovieDBBase" connectionString="Data Source=(localdb)\mssqllocaldb;Initial Catalog=MovieDBDev" providerName="System.Data.SqlClient"/>
|
||||
</connectionStrings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
|
||||
<parameters>
|
||||
<parameter value="mssqllocaldb" />
|
||||
</parameters>
|
||||
</defaultConnectionFactory>
|
||||
<providers>
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||
</providers>
|
||||
</entityFramework>
|
||||
</configuration>
|
33
MovieDB/Migrations/Configuration.cs
Normal file
33
MovieDB/Migrations/Configuration.cs
Normal file
@ -0,0 +1,33 @@
|
||||
namespace MovieDB.Migrations
|
||||
{
|
||||
using System;
|
||||
using System.Data.Entity;
|
||||
using System.Data.Entity.Migrations;
|
||||
using System.Linq;
|
||||
|
||||
internal sealed class Configuration : DbMigrationsConfiguration<MovieDB.MovieDBContext>
|
||||
{
|
||||
public Configuration()
|
||||
{
|
||||
AutomaticMigrationsEnabled = true;
|
||||
ContextKey = "MovieDB.MovieDBContext";
|
||||
AutomaticMigrationDataLossAllowed = true;
|
||||
}
|
||||
|
||||
protected override void Seed(MovieDB.MovieDBContext context)
|
||||
{
|
||||
// This method will be called after migrating to the latest version.
|
||||
|
||||
// You can use the DbSet<T>.AddOrUpdate() helper extension method
|
||||
// to avoid creating duplicate seed data. E.g.
|
||||
//
|
||||
// context.People.AddOrUpdate(
|
||||
// p => p.FullName,
|
||||
// new Person { FullName = "Andrew Peters" },
|
||||
// new Person { FullName = "Brice Lambson" },
|
||||
// new Person { FullName = "Rowan Miller" }
|
||||
// );
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
71
MovieDB/MovieDB.csproj
Normal file
71
MovieDB/MovieDB.csproj
Normal file
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<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>{619CD7DD-A0E4-47FF-AE45-608678F25166}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>MovieDB</RootNamespace>
|
||||
<AssemblyName>MovieDB</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<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' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<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.1.3\lib\net45\EntityFramework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</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="Migrations\Configuration.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
147
MovieDB/Program.cs
Normal file
147
MovieDB/Program.cs
Normal file
@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data.Entity;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MovieDB.Migrations;
|
||||
|
||||
namespace MovieDB
|
||||
{
|
||||
public class Movie
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
[Required]
|
||||
public int Year { get; set; }
|
||||
public List<string> Zanrs { get; set; }
|
||||
public virtual List<ActorRole> Actors { get; set; }
|
||||
|
||||
public Movie()
|
||||
{
|
||||
this.Zanrs = new List<string>();
|
||||
this.Actors = new List<ActorRole>();
|
||||
}
|
||||
}
|
||||
|
||||
public class ActorRole
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Role { get; set; }
|
||||
[Required]
|
||||
public Actor Actor { get; set; }
|
||||
}
|
||||
|
||||
public class Actor
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string FirstName { get; set; }
|
||||
[Required]
|
||||
public string LastName { get; set; }
|
||||
[Required]
|
||||
public bool Active { get; set; }
|
||||
[Required]
|
||||
public int BirthYear { get; set; }
|
||||
public virtual List<Movie> Movies { get; set; }
|
||||
|
||||
public Actor ()
|
||||
{
|
||||
this.Active = true;
|
||||
this.Movies = new List<Movie>();
|
||||
}
|
||||
}
|
||||
|
||||
public class MovieDBContext : DbContext
|
||||
{
|
||||
public DbSet<Movie> Movies { get; set; }
|
||||
public DbSet<ActorRole> ActorRoles { get; set; }
|
||||
public DbSet<Actor> Actors { get; set; }
|
||||
|
||||
public MovieDBContext() : base("name=MovieDBBase")
|
||||
{
|
||||
Database.SetInitializer(
|
||||
new MigrateDatabaseToLatestVersion<MovieDBContext, Configuration>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
using (MovieDBContext db = new MovieDBContext())
|
||||
{
|
||||
bool running = true;
|
||||
while (running)
|
||||
{
|
||||
Console.Write("> ");
|
||||
string[] input = Console.ReadLine().Split(' ');
|
||||
switch (input[0])
|
||||
{
|
||||
case "exit":
|
||||
running = false;
|
||||
break;
|
||||
case "listmovies":
|
||||
foreach (var movie in db.Movies)
|
||||
{
|
||||
Console.WriteLine($"{movie.Id}: {movie.Name} ({movie.Year})");
|
||||
}
|
||||
Console.WriteLine($"Movie count: {db.Movies.Count()}");
|
||||
break;
|
||||
case "addmovie":
|
||||
var m = new Movie();
|
||||
m.Name = input[1];
|
||||
m.Year = int.Parse(input[2]);
|
||||
db.Movies.Add(m);
|
||||
db.SaveChanges();
|
||||
break;
|
||||
|
||||
case "addactor":
|
||||
var a = new Actor();
|
||||
a.FirstName = input[1];
|
||||
a.LastName = input[2];
|
||||
a.BirthYear = int.Parse(input[3]);
|
||||
db.Actors.Add(a);
|
||||
db.SaveChanges();
|
||||
break;
|
||||
case "listactors":
|
||||
foreach (var actor in db.Actors)
|
||||
{
|
||||
Console.WriteLine($"{actor.Id}: {actor.FirstName} {actor.LastName} ({actor.BirthYear}), movie count: {actor.Movies.Count()}");
|
||||
}
|
||||
Console.WriteLine($"Actor count: {db.Actors.Count()}");
|
||||
break;
|
||||
|
||||
case "addactormovie":
|
||||
var ar = new ActorRole();
|
||||
var am = db.Movies.Find(int.Parse(input[1]));
|
||||
am.Actors.Add(ar);
|
||||
ar.Actor = db.Actors.Find(int.Parse(input[2]));
|
||||
ar.Role = input[3];
|
||||
break;
|
||||
|
||||
case "listactormovie":
|
||||
var mov = db.Movies.Find(int.Parse(input[1]));
|
||||
foreach (var actor in mov.Actors)
|
||||
{
|
||||
Console.WriteLine($"{actor.Id}: {actor.Actor.FirstName} {actor.Actor.LastName} ({actor.Actor.BirthYear}) {actor.Role}");
|
||||
}
|
||||
Console.WriteLine($"Number of actors for movie {mov.Name}: {mov.Actors.Count}");
|
||||
break;
|
||||
case "help":
|
||||
Console.WriteLine("listmovies: Lists all movies\naddmovie <name> <year>: Adds a movie\nlistactors: List all actors\naddactor <FirstName> <LastName> <BirthYear>: Add a new actor\nlistactormovie <MovieId>: List actors for a movie\naddactormovie <MovieId> <ActorId> <Role>: Add a actor to a movie with a role");
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("No such command. Try help.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
36
MovieDB/Properties/AssemblyInfo.cs
Normal file
36
MovieDB/Properties/AssemblyInfo.cs
Normal file
@ -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("MovieDB")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("MovieDB")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[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("619cd7dd-a0e4-47ff-ae45-608678f25166")]
|
||||
|
||||
// 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")]
|
4
MovieDB/packages.config
Normal file
4
MovieDB/packages.config
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
|
||||
</packages>
|
22
MovieDBSolution.sln
Normal file
22
MovieDBSolution.sln
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MovieDB", "MovieDB\MovieDB.csproj", "{619CD7DD-A0E4-47FF-AE45-608678F25166}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{619CD7DD-A0E4-47FF-AE45-608678F25166}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{619CD7DD-A0E4-47FF-AE45-608678F25166}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{619CD7DD-A0E4-47FF-AE45-608678F25166}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{619CD7DD-A0E4-47FF-AE45-608678F25166}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Loading…
Reference in New Issue
Block a user