diff --git a/MovieDB/App.config b/MovieDB/App.config new file mode 100644 index 0000000..b9df17a --- /dev/null +++ b/MovieDB/App.config @@ -0,0 +1,23 @@ + + + + +
+ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MovieDB/Migrations/Configuration.cs b/MovieDB/Migrations/Configuration.cs new file mode 100644 index 0000000..f1e09d5 --- /dev/null +++ b/MovieDB/Migrations/Configuration.cs @@ -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 + { + 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.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" } + // ); + // + } + } +} diff --git a/MovieDB/MovieDB.csproj b/MovieDB/MovieDB.csproj new file mode 100644 index 0000000..adb071d --- /dev/null +++ b/MovieDB/MovieDB.csproj @@ -0,0 +1,71 @@ + + + + + Debug + AnyCPU + {619CD7DD-A0E4-47FF-AE45-608678F25166} + Exe + Properties + MovieDB + MovieDB + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + True + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + True + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MovieDB/Program.cs b/MovieDB/Program.cs new file mode 100644 index 0000000..1194589 --- /dev/null +++ b/MovieDB/Program.cs @@ -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 Zanrs { get; set; } + public virtual List Actors { get; set; } + + public Movie() + { + this.Zanrs = new List(); + this.Actors = new List(); + } + } + + 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 Movies { get; set; } + + public Actor () + { + this.Active = true; + this.Movies = new List(); + } + } + + public class MovieDBContext : DbContext + { + public DbSet Movies { get; set; } + public DbSet ActorRoles { get; set; } + public DbSet Actors { get; set; } + + public MovieDBContext() : base("name=MovieDBBase") + { + Database.SetInitializer( + new MigrateDatabaseToLatestVersion()); + } + } + + + 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 : Adds a movie\nlistactors: List all actors\naddactor : Add a new actor\nlistactormovie : List actors for a movie\naddactormovie : Add a actor to a movie with a role"); + break; + default: + Console.WriteLine("No such command. Try help."); + break; + } + } + } + } + } +} \ No newline at end of file diff --git a/MovieDB/Properties/AssemblyInfo.cs b/MovieDB/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ba0811e --- /dev/null +++ b/MovieDB/Properties/AssemblyInfo.cs @@ -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")] diff --git a/MovieDB/packages.config b/MovieDB/packages.config new file mode 100644 index 0000000..4409173 --- /dev/null +++ b/MovieDB/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/MovieDBSolution.sln b/MovieDBSolution.sln new file mode 100644 index 0000000..7dcfd93 --- /dev/null +++ b/MovieDBSolution.sln @@ -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