commit d3b7ff17bea3cbb09c0d41303cfecfd203fd71f3 Author: Tommy Öman Date: Mon Aug 22 15:56:12 2022 +0200 initial load diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9491a2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,363 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd \ No newline at end of file diff --git a/YouTubeViewers.Domain/Commands/ICreateYouTubeViewerCommand.cs b/YouTubeViewers.Domain/Commands/ICreateYouTubeViewerCommand.cs new file mode 100644 index 0000000..021a710 --- /dev/null +++ b/YouTubeViewers.Domain/Commands/ICreateYouTubeViewerCommand.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.Domain.Models; + +namespace YouTubeViewers.Domain.Commands +{ + public interface ICreateYouTubeViewerCommand + { + Task Execute(YouTubeViewer youTubeViewer); + } +} diff --git a/YouTubeViewers.Domain/Commands/IDeleteYouTubeViewerCommand.cs b/YouTubeViewers.Domain/Commands/IDeleteYouTubeViewerCommand.cs new file mode 100644 index 0000000..f5e6f93 --- /dev/null +++ b/YouTubeViewers.Domain/Commands/IDeleteYouTubeViewerCommand.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace YouTubeViewers.Domain.Commands +{ + public interface IDeleteYouTubeViewerCommand + { + Task Execute(Guid id); + } +} diff --git a/YouTubeViewers.Domain/Commands/IUpdateYouTubeViewerCommand.cs b/YouTubeViewers.Domain/Commands/IUpdateYouTubeViewerCommand.cs new file mode 100644 index 0000000..d108ffa --- /dev/null +++ b/YouTubeViewers.Domain/Commands/IUpdateYouTubeViewerCommand.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.Domain.Models; + +namespace YouTubeViewers.Domain.Commands +{ + public interface IUpdateYouTubeViewerCommand + { + Task Execute(YouTubeViewer youTubeViewer); + } +} diff --git a/YouTubeViewers.Domain/Models/YouTubeViewer.cs b/YouTubeViewers.Domain/Models/YouTubeViewer.cs new file mode 100644 index 0000000..2e9ebbb --- /dev/null +++ b/YouTubeViewers.Domain/Models/YouTubeViewer.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace YouTubeViewers.Domain.Models +{ + public class YouTubeViewer + { + public YouTubeViewer(Guid id, string username, bool isSubscribed, bool isMember) + { + Id = id; + Username = username; + IsSubscribed = isSubscribed; + IsMember = isMember; + } + + public Guid Id { get; } + public string Username { get; } + public bool IsSubscribed { get; } + public bool IsMember { get; } + } +} diff --git a/YouTubeViewers.Domain/Queries/IGetAllYouTubeViewersQuery.cs b/YouTubeViewers.Domain/Queries/IGetAllYouTubeViewersQuery.cs new file mode 100644 index 0000000..aabb179 --- /dev/null +++ b/YouTubeViewers.Domain/Queries/IGetAllYouTubeViewersQuery.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.Domain.Models; + +namespace YouTubeViewers.Domain.Queries +{ + public interface IGetAllYouTubeViewersQuery + { + Task> Execute(); + } +} diff --git a/YouTubeViewers.Domain/YouTubeViewers.Domain.csproj b/YouTubeViewers.Domain/YouTubeViewers.Domain.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/YouTubeViewers.Domain/YouTubeViewers.Domain.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/YouTubeViewers.EntityFramework/Commands/CreateYouTubeViewerCommand.cs b/YouTubeViewers.EntityFramework/Commands/CreateYouTubeViewerCommand.cs new file mode 100644 index 0000000..c74c930 --- /dev/null +++ b/YouTubeViewers.EntityFramework/Commands/CreateYouTubeViewerCommand.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.Domain.Commands; +using YouTubeViewers.Domain.Models; +using YouTubeViewers.EntityFramework.DTOs; + +namespace YouTubeViewers.EntityFramework.Commands +{ + public class CreateYouTubeViewerCommand :ICreateYouTubeViewerCommand + { + private readonly YouTubeViewersDbContextFactory _contextFactory; + + public CreateYouTubeViewerCommand(YouTubeViewersDbContextFactory contextFactory) + { + _contextFactory = contextFactory; + } + + public async Task Execute(YouTubeViewer youTubeViewer) + { + using (YouTubeViewersDbContext context = _contextFactory.Create()) + { + YouTubeViewerDto youTubeViewerDto = new YouTubeViewerDto() + { + Id = youTubeViewer.Id, + Username = youTubeViewer.Username, + IsSubscribed = youTubeViewer.IsSubscribed, + IsMember = youTubeViewer.IsMember, + }; + + context.YouTubeViewers.Add(youTubeViewerDto); + await context.SaveChangesAsync(); + } + } + } +} diff --git a/YouTubeViewers.EntityFramework/Commands/DeleteYouTubeViewerCommand.cs b/YouTubeViewers.EntityFramework/Commands/DeleteYouTubeViewerCommand.cs new file mode 100644 index 0000000..52a27d3 --- /dev/null +++ b/YouTubeViewers.EntityFramework/Commands/DeleteYouTubeViewerCommand.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.Domain.Commands; +using YouTubeViewers.EntityFramework.DTOs; + +namespace YouTubeViewers.EntityFramework.Commands +{ + public class DeleteYouTubeViewerCommand : IDeleteYouTubeViewerCommand + { + private readonly YouTubeViewersDbContextFactory _contextFactory; + + public DeleteYouTubeViewerCommand(YouTubeViewersDbContextFactory contextFactory) + { + _contextFactory = contextFactory; + } + + public async Task Execute(Guid id) + { + using (YouTubeViewersDbContext context = _contextFactory.Create()) + { + await Task.Delay(5000); + YouTubeViewerDto youTubeViewerDto = new YouTubeViewerDto() + { + Id = id, + }; + + context.YouTubeViewers.Remove(youTubeViewerDto); + await context.SaveChangesAsync(); + } + } + } +} diff --git a/YouTubeViewers.EntityFramework/Commands/UpdateYouTubeViewerCommand.cs b/YouTubeViewers.EntityFramework/Commands/UpdateYouTubeViewerCommand.cs new file mode 100644 index 0000000..afc68d9 --- /dev/null +++ b/YouTubeViewers.EntityFramework/Commands/UpdateYouTubeViewerCommand.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.Domain.Commands; +using YouTubeViewers.Domain.Models; +using YouTubeViewers.EntityFramework.DTOs; + +namespace YouTubeViewers.EntityFramework.Commands +{ + public class UpdateYouTubeViewerCommand : IUpdateYouTubeViewerCommand + { + private readonly YouTubeViewersDbContextFactory _contextFactory; + + public UpdateYouTubeViewerCommand(YouTubeViewersDbContextFactory contextFactory) + { + _contextFactory = contextFactory; + } + + public async Task Execute(YouTubeViewer youTubeViewer) + { + using (YouTubeViewersDbContext context = _contextFactory.Create()) + { + YouTubeViewerDto youTubeViewerDto = new YouTubeViewerDto() + { + Id = youTubeViewer.Id, + Username = youTubeViewer.Username, + IsSubscribed = youTubeViewer.IsSubscribed, + IsMember = youTubeViewer.IsMember, + }; + + context.YouTubeViewers.Update(youTubeViewerDto); + await context.SaveChangesAsync(); + } + } + } +} diff --git a/YouTubeViewers.EntityFramework/DTOs/YouTubeViewerDto.cs b/YouTubeViewers.EntityFramework/DTOs/YouTubeViewerDto.cs new file mode 100644 index 0000000..8c83f63 --- /dev/null +++ b/YouTubeViewers.EntityFramework/DTOs/YouTubeViewerDto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace YouTubeViewers.EntityFramework.DTOs +{ + public class YouTubeViewerDto + { + public Guid Id { get; set; } + public string Username { get; set; } + public bool IsSubscribed { get; set; } + public bool IsMember { get; set; } + } +} diff --git a/YouTubeViewers.EntityFramework/Migrations/20220819131646_Initial.Designer.cs b/YouTubeViewers.EntityFramework/Migrations/20220819131646_Initial.Designer.cs new file mode 100644 index 0000000..3cbbc0a --- /dev/null +++ b/YouTubeViewers.EntityFramework/Migrations/20220819131646_Initial.Designer.cs @@ -0,0 +1,45 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using YouTubeViewers.EntityFramework; + +#nullable disable + +namespace YouTubeViewers.EntityFramework.Migrations +{ + [DbContext(typeof(YouTubeViewersDbContext))] + [Migration("20220819131646_Initial")] + partial class Initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "6.0.8"); + + modelBuilder.Entity("YouTubeViewers.EntityFramework.DTOs.YouTubeViewerDto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("IsMember") + .HasColumnType("INTEGER"); + + b.Property("IsSubscribed") + .HasColumnType("INTEGER"); + + b.Property("Username") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("YouTubeViewers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/YouTubeViewers.EntityFramework/Migrations/20220819131646_Initial.cs b/YouTubeViewers.EntityFramework/Migrations/20220819131646_Initial.cs new file mode 100644 index 0000000..6180682 --- /dev/null +++ b/YouTubeViewers.EntityFramework/Migrations/20220819131646_Initial.cs @@ -0,0 +1,33 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace YouTubeViewers.EntityFramework.Migrations +{ + public partial class Initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "YouTubeViewers", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Username = table.Column(type: "TEXT", nullable: false), + IsSubscribed = table.Column(type: "INTEGER", nullable: false), + IsMember = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_YouTubeViewers", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "YouTubeViewers"); + } + } +} diff --git a/YouTubeViewers.EntityFramework/Migrations/YouTubeViewersDbContextModelSnapshot.cs b/YouTubeViewers.EntityFramework/Migrations/YouTubeViewersDbContextModelSnapshot.cs new file mode 100644 index 0000000..6c3227b --- /dev/null +++ b/YouTubeViewers.EntityFramework/Migrations/YouTubeViewersDbContextModelSnapshot.cs @@ -0,0 +1,43 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using YouTubeViewers.EntityFramework; + +#nullable disable + +namespace YouTubeViewers.EntityFramework.Migrations +{ + [DbContext(typeof(YouTubeViewersDbContext))] + partial class YouTubeViewersDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "6.0.8"); + + modelBuilder.Entity("YouTubeViewers.EntityFramework.DTOs.YouTubeViewerDto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("IsMember") + .HasColumnType("INTEGER"); + + b.Property("IsSubscribed") + .HasColumnType("INTEGER"); + + b.Property("Username") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("YouTubeViewers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/YouTubeViewers.EntityFramework/Queries/GetAllYouTubeViewersQuery.cs b/YouTubeViewers.EntityFramework/Queries/GetAllYouTubeViewersQuery.cs new file mode 100644 index 0000000..52ab506 --- /dev/null +++ b/YouTubeViewers.EntityFramework/Queries/GetAllYouTubeViewersQuery.cs @@ -0,0 +1,34 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.Domain.Models; +using YouTubeViewers.Domain.Queries; +using YouTubeViewers.EntityFramework.DTOs; + +namespace YouTubeViewers.EntityFramework.Queries +{ + public class GetAllYouTubeViewersQuery : IGetAllYouTubeViewersQuery + { + private readonly YouTubeViewersDbContextFactory _contextFactory; + + public GetAllYouTubeViewersQuery(YouTubeViewersDbContextFactory contextFactory) + { + _contextFactory = contextFactory; + } + + public async Task> Execute() + { + using (YouTubeViewersDbContext context = _contextFactory.Create()) + { + //await Task.Delay(5000); + + IEnumerable youTubeViewerDtos = await context.YouTubeViewers.ToListAsync(); + + return youTubeViewerDtos.Select(y => new YouTubeViewer(y.Id, y.Username, y.IsSubscribed, y.IsMember)); + } + } + } +} diff --git a/YouTubeViewers.EntityFramework/YouTubeViewers.EntityFramework.csproj b/YouTubeViewers.EntityFramework/YouTubeViewers.EntityFramework.csproj new file mode 100644 index 0000000..ee3f970 --- /dev/null +++ b/YouTubeViewers.EntityFramework/YouTubeViewers.EntityFramework.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/YouTubeViewers.EntityFramework/YouTubeViewersDbContext.cs b/YouTubeViewers.EntityFramework/YouTubeViewersDbContext.cs new file mode 100644 index 0000000..7aab8bb --- /dev/null +++ b/YouTubeViewers.EntityFramework/YouTubeViewersDbContext.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.EntityFramework.DTOs; + +namespace YouTubeViewers.EntityFramework +{ + public class YouTubeViewersDbContext : DbContext + { + public YouTubeViewersDbContext(DbContextOptions options) : base(options) { } + + public DbSet YouTubeViewers { get; set; } + + //DbContextOptions options = new DbContextOptionsBuilder() + // .UseSqlite(_connectionString) + // .Options; + + + } + +} diff --git a/YouTubeViewers.EntityFramework/YouTubeViewersDbContextFactory.cs b/YouTubeViewers.EntityFramework/YouTubeViewersDbContextFactory.cs new file mode 100644 index 0000000..d8d7c32 --- /dev/null +++ b/YouTubeViewers.EntityFramework/YouTubeViewersDbContextFactory.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace YouTubeViewers.EntityFramework +{ + public class YouTubeViewersDbContextFactory + { + private readonly DbContextOptions _options; + + public YouTubeViewersDbContextFactory(DbContextOptions options) + { + _options = options; + } + + public YouTubeViewersDbContext Create() + { + + return new YouTubeViewersDbContext(_options); + } + } +} diff --git a/YouTubeViewers.EntityFramework/YouTubeViewersDesignTimeDbContextFactory.cs b/YouTubeViewers.EntityFramework/YouTubeViewersDesignTimeDbContextFactory.cs new file mode 100644 index 0000000..6cb05ab --- /dev/null +++ b/YouTubeViewers.EntityFramework/YouTubeViewersDesignTimeDbContextFactory.cs @@ -0,0 +1,18 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace YouTubeViewers.EntityFramework +{ + public class YouTubeViewersDesignTimeDbContextFactory : IDesignTimeDbContextFactory + { + public YouTubeViewersDbContext CreateDbContext(string[] args = null) + { + return new YouTubeViewersDbContext(new DbContextOptionsBuilder().UseSqlite("Data Source=YouTubeViewers.db").Options); + } + } +} diff --git a/YouTubeViewers.WPF/App.xaml b/YouTubeViewers.WPF/App.xaml new file mode 100644 index 0000000..025ae7c --- /dev/null +++ b/YouTubeViewers.WPF/App.xaml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + diff --git a/YouTubeViewers.WPF/App.xaml.cs b/YouTubeViewers.WPF/App.xaml.cs new file mode 100644 index 0000000..25322da --- /dev/null +++ b/YouTubeViewers.WPF/App.xaml.cs @@ -0,0 +1,78 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; +using YouTubeViewers.Domain.Commands; +using YouTubeViewers.Domain.Queries; +using YouTubeViewers.EntityFramework; +using YouTubeViewers.EntityFramework.Commands; +using YouTubeViewers.EntityFramework.Queries; +using YouTubeViewers.WPF.Stores; +using YouTubeViewers.WPF.ViewModels; + +namespace YouTubeViewers.WPF; + +public partial class App : Application +{ + private readonly ModalNavigationStore _modalNavigationStore; + private readonly YouTubeViewersDbContextFactory _youTubeViewersDbContextFactory; + private readonly IGetAllYouTubeViewersQuery _getAllYouTubeViewersQuery; + private readonly ICreateYouTubeViewerCommand _createYouTubeViewerCommand; + private readonly IUpdateYouTubeViewerCommand _updateYouTubeViewerCommand; + private readonly IDeleteYouTubeViewerCommand _deleteYouTubeViewerCommand; + private readonly YouTubeViewersStore _youTubeViewersStore; + private readonly SelectedYouTubeViewerStore _selectedYouTubeViewerStore; + + public App() + { + string connectionString = "Data Source=YouTubeViewers.db"; + _modalNavigationStore = new ModalNavigationStore(); + _youTubeViewersDbContextFactory = new YouTubeViewersDbContextFactory( + new DbContextOptionsBuilder() + .UseSqlite(connectionString) + .Options + ); + _getAllYouTubeViewersQuery = new GetAllYouTubeViewersQuery(_youTubeViewersDbContextFactory); + _createYouTubeViewerCommand = new CreateYouTubeViewerCommand(_youTubeViewersDbContextFactory); + _updateYouTubeViewerCommand = new UpdateYouTubeViewerCommand(_youTubeViewersDbContextFactory); + _deleteYouTubeViewerCommand = new DeleteYouTubeViewerCommand(_youTubeViewersDbContextFactory); + _youTubeViewersStore = new YouTubeViewersStore( + _getAllYouTubeViewersQuery, + _createYouTubeViewerCommand, + _updateYouTubeViewerCommand, + _deleteYouTubeViewerCommand + ); + _selectedYouTubeViewerStore = new SelectedYouTubeViewerStore(_youTubeViewersStore); + } + + protected override void OnStartup(StartupEventArgs e) + { + using(YouTubeViewersDbContext context = _youTubeViewersDbContextFactory.Create()) + { + //context.Database.EnsureCreated(); + context.Database.Migrate(); + } + + YouTubeViewersViewModel youTubeViewersViewModel = YouTubeViewersViewModel.LoadViewModel( + _youTubeViewersStore, + _selectedYouTubeViewerStore, + _modalNavigationStore); + + MainWindow = new MainWindow() + { + DataContext = new MainViewModel(_modalNavigationStore, youTubeViewersViewModel) + }; + + MainWindow.Show(); + + base.OnStartup(e); + } +} + + + + diff --git a/YouTubeViewers.WPF/AssemblyInfo.cs b/YouTubeViewers.WPF/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/YouTubeViewers.WPF/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/YouTubeViewers.WPF/Commands/AddYouTubeViewerCommand.cs b/YouTubeViewers.WPF/Commands/AddYouTubeViewerCommand.cs new file mode 100644 index 0000000..9015639 --- /dev/null +++ b/YouTubeViewers.WPF/Commands/AddYouTubeViewerCommand.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.Domain.Models; +using YouTubeViewers.WPF.Stores; +using YouTubeViewers.WPF.ViewModels; + +namespace YouTubeViewers.WPF.Commands +{ + public class AddYouTubeViewerCommand : AsyncCommandBase + { + private readonly AddYouTubeViewerViewModel _addYouTubeViewerViewModel; + private readonly YouTubeViewersStore _youTubeViewersStore; + private readonly ModalNavigationStore _modalNavigationStore; + + public AddYouTubeViewerCommand(AddYouTubeViewerViewModel addYouTubeViewerViewModel, YouTubeViewersStore youTubeViewersStore, ModalNavigationStore modalNavigationStore) + { + _addYouTubeViewerViewModel = addYouTubeViewerViewModel; + _youTubeViewersStore = youTubeViewersStore; + _modalNavigationStore = modalNavigationStore; + } + public override async Task ExecuteAsync(object? parameter) + { + YouTubeViewerDetailsFormViewModel formViewModel = _addYouTubeViewerViewModel.YouTubeViewerDetailsFormViewModel; + formViewModel.IsSubmitting = true; + YouTubeViewer youTubeViewer = new YouTubeViewer( + Guid.NewGuid(), + formViewModel.UserName, + formViewModel.IsSubScribed, + formViewModel.IsMember); + + // Add YouTubeViewer to database + try + { + await _youTubeViewersStore.Add(youTubeViewer); + _modalNavigationStore.Close(); + } + catch (Exception) + { + throw; + } + finally + { + formViewModel.IsSubmitting = false; + } + } + } +} diff --git a/YouTubeViewers.WPF/Commands/AsyncCommandBase.cs b/YouTubeViewers.WPF/Commands/AsyncCommandBase.cs new file mode 100644 index 0000000..f9230b5 --- /dev/null +++ b/YouTubeViewers.WPF/Commands/AsyncCommandBase.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace YouTubeViewers.WPF.Commands +{ + public abstract class AsyncCommandBase : CommandBase + { + private bool _isExecuting; + + public bool IsExecuting + { + get { return _isExecuting; } + set { _isExecuting = value; + OnCanExecuteChanged(); + } + } + + public override bool CanExecute(object? parameter) + { + return !_isExecuting && base.CanExecute(parameter); + } + + + public override async void Execute(object? parameter) + { + IsExecuting = true; + + try + { + await ExecuteAsync(parameter); + } + catch (Exception) { } + finally + { + IsExecuting = false; + } + } + + public abstract Task ExecuteAsync(object? parameter); + } +} diff --git a/YouTubeViewers.WPF/Commands/CloseModalCommand.cs b/YouTubeViewers.WPF/Commands/CloseModalCommand.cs new file mode 100644 index 0000000..3591be1 --- /dev/null +++ b/YouTubeViewers.WPF/Commands/CloseModalCommand.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.WPF.Stores; + +namespace YouTubeViewers.WPF.Commands +{ + public class CloseModalCommand : CommandBase + { + private readonly ModalNavigationStore _modalNavigationStore; + + public CloseModalCommand(ModalNavigationStore modalNavigationStore) + { + _modalNavigationStore = modalNavigationStore; + } + + public override void Execute(object? parameter) + { + _modalNavigationStore.Close(); + } + } +} diff --git a/YouTubeViewers.WPF/Commands/CommandBase.cs b/YouTubeViewers.WPF/Commands/CommandBase.cs new file mode 100644 index 0000000..9a58af3 --- /dev/null +++ b/YouTubeViewers.WPF/Commands/CommandBase.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace YouTubeViewers.WPF.Commands +{ + public abstract class CommandBase : ICommand + { + public event EventHandler? CanExecuteChanged; + + public virtual bool CanExecute(object? parameter) + { + return true; + } + + public abstract void Execute(object? parameter); + + protected virtual void OnCanExecuteChanged() + { + CanExecuteChanged?.Invoke(this, EventArgs.Empty); + } + } +} diff --git a/YouTubeViewers.WPF/Commands/DeleteYouTubeViewerCommand.cs b/YouTubeViewers.WPF/Commands/DeleteYouTubeViewerCommand.cs new file mode 100644 index 0000000..041c776 --- /dev/null +++ b/YouTubeViewers.WPF/Commands/DeleteYouTubeViewerCommand.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.Domain.Models; +using YouTubeViewers.WPF.Stores; +using YouTubeViewers.WPF.ViewModels; + +namespace YouTubeViewers.WPF.Commands +{ + public class DeleteYouTubeViewerCommand : AsyncCommandBase + { + private readonly YouTubeViewersListingItemViewModel _youTubeViewersListingItemViewModel; + private readonly YouTubeViewersStore _youTubeViewersStore; + + public DeleteYouTubeViewerCommand( + YouTubeViewersListingItemViewModel youTubeViewersListingItemViewModel, + YouTubeViewersStore youTubeViewersStore) + { + _youTubeViewersListingItemViewModel = youTubeViewersListingItemViewModel; + _youTubeViewersStore = youTubeViewersStore; + + } + + public override async Task ExecuteAsync(object? parameter) + { + YouTubeViewer youTubeViewer = _youTubeViewersListingItemViewModel.YouTubeViewer; + try + { + await _youTubeViewersStore.Delete(youTubeViewer.Id); + } + catch (Exception) + { + throw; + } + } + } +} \ No newline at end of file diff --git a/YouTubeViewers.WPF/Commands/EditYouTubeViewerCommand.cs b/YouTubeViewers.WPF/Commands/EditYouTubeViewerCommand.cs new file mode 100644 index 0000000..2b9dd32 --- /dev/null +++ b/YouTubeViewers.WPF/Commands/EditYouTubeViewerCommand.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.Domain.Models; +using YouTubeViewers.WPF.Stores; +using YouTubeViewers.WPF.ViewModels; + +namespace YouTubeViewers.WPF.Commands +{ + public class EditYouTubeViewerCommand : AsyncCommandBase + { + private readonly EditYouTubeViewerViewModel _editYouTubeViewerViewModel; + private readonly YouTubeViewersStore _youTubeViewersStore; + private readonly ModalNavigationStore _modalNavigationStore; + + public EditYouTubeViewerCommand(EditYouTubeViewerViewModel editYouTubeViewerViewModel, YouTubeViewersStore youTubeViewersStore, ModalNavigationStore modalNavigationStore) + { + _editYouTubeViewerViewModel = editYouTubeViewerViewModel; + _youTubeViewersStore = youTubeViewersStore; + _modalNavigationStore = modalNavigationStore; + } + public override async Task ExecuteAsync(object? parameter) + { + YouTubeViewerDetailsFormViewModel formViewModel = _editYouTubeViewerViewModel.YouTubeViewerDetailsFormViewModel; + formViewModel.IsSubmitting = true; + YouTubeViewer youTubeViewer = new YouTubeViewer( + _editYouTubeViewerViewModel.YouTubeViewerId, + formViewModel.UserName, + formViewModel.IsSubScribed, + formViewModel.IsMember); + + // Add YouTubeViewer to database + try + { + await _youTubeViewersStore.Update(youTubeViewer); + _modalNavigationStore.Close(); + } + catch (Exception) + { + throw; + } + finally + { + formViewModel.IsSubmitting = false; + } + } + } +} diff --git a/YouTubeViewers.WPF/Commands/LoadYouTubeViewersCommand.cs b/YouTubeViewers.WPF/Commands/LoadYouTubeViewersCommand.cs new file mode 100644 index 0000000..43a6ec7 --- /dev/null +++ b/YouTubeViewers.WPF/Commands/LoadYouTubeViewersCommand.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.WPF.Stores; +using YouTubeViewers.WPF.ViewModels; + +namespace YouTubeViewers.WPF.Commands +{ + public class LoadYouTubeViewersCommand : AsyncCommandBase + { + private readonly YouTubeViewersViewModel _youTubeViewersViewModel; + private readonly YouTubeViewersStore _youTubeViewersStore; + + public LoadYouTubeViewersCommand(YouTubeViewersViewModel youTubeViewersViewModel, YouTubeViewersStore youTubeViewersStore) + { + _youTubeViewersViewModel = youTubeViewersViewModel; + _youTubeViewersStore = youTubeViewersStore; + } + + public override async Task ExecuteAsync(object? parameter) + { + _youTubeViewersViewModel.IsLoading = true; + + try + { + await _youTubeViewersStore.Load(); + } + catch (Exception) + { + throw; + } + finally + { + _youTubeViewersViewModel.IsLoading = false; + } + } + } +} diff --git a/YouTubeViewers.WPF/Commands/OpenAddYouTubeViewerCommand.cs b/YouTubeViewers.WPF/Commands/OpenAddYouTubeViewerCommand.cs new file mode 100644 index 0000000..d78ef02 --- /dev/null +++ b/YouTubeViewers.WPF/Commands/OpenAddYouTubeViewerCommand.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; +using YouTubeViewers.WPF.Stores; +using YouTubeViewers.WPF.ViewModels; + +namespace YouTubeViewers.WPF.Commands +{ + public class OpenAddYouTubeViewerCommand : CommandBase + { + private readonly YouTubeViewersStore _youTubeViewersStore; + private readonly ModalNavigationStore _modalNavigationStore; + + public OpenAddYouTubeViewerCommand(YouTubeViewersStore youTubeViewersStore, ModalNavigationStore modalNavigationStore) + { + _youTubeViewersStore = youTubeViewersStore; + _modalNavigationStore = modalNavigationStore; + } + + public override void Execute(object? parameter) + { + AddYouTubeViewerViewModel addYouTubeViewerViewModel = new AddYouTubeViewerViewModel(_youTubeViewersStore, _modalNavigationStore); + _modalNavigationStore.CurrentViewModel = addYouTubeViewerViewModel; + } + } +} diff --git a/YouTubeViewers.WPF/Commands/OpenEditYouTubeViewerCommand.cs b/YouTubeViewers.WPF/Commands/OpenEditYouTubeViewerCommand.cs new file mode 100644 index 0000000..762a220 --- /dev/null +++ b/YouTubeViewers.WPF/Commands/OpenEditYouTubeViewerCommand.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YouTubeViewers.Domain.Models; +using YouTubeViewers.WPF.Stores; +using YouTubeViewers.WPF.ViewModels; + +namespace YouTubeViewers.WPF.Commands +{ + public class OpenEditYouTubeViewerCommand: CommandBase + { + private readonly YouTubeViewersListingItemViewModel _youTubeViewersListingItemViewModel; + private readonly YouTubeViewersStore _youTubeViewersStore; + private readonly ModalNavigationStore _modalNavigationStore; + + public OpenEditYouTubeViewerCommand( + YouTubeViewersListingItemViewModel youTubeViewersListingItemViewModel, + YouTubeViewersStore youTubeViewersStore, + ModalNavigationStore modalNavigationStore) + { + _youTubeViewersListingItemViewModel = youTubeViewersListingItemViewModel; + _youTubeViewersStore = youTubeViewersStore; + _modalNavigationStore = modalNavigationStore; + } + + public override void Execute(object? parameter) + { + YouTubeViewer youTubeViewer = _youTubeViewersListingItemViewModel.YouTubeViewer; + + EditYouTubeViewerViewModel editYouTubeViewerViewModel = new EditYouTubeViewerViewModel(youTubeViewer,_youTubeViewersStore, _modalNavigationStore); + _modalNavigationStore.CurrentViewModel = editYouTubeViewerViewModel; + } + } + +} + diff --git a/YouTubeViewers.WPF/Components/YouTubeViewerDetailsForm.xaml b/YouTubeViewers.WPF/Components/YouTubeViewerDetailsForm.xaml new file mode 100644 index 0000000..cb258b8 --- /dev/null +++ b/YouTubeViewers.WPF/Components/YouTubeViewerDetailsForm.xaml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +