diff --git a/DaSaSo.ConsoleApp/Program.cs b/DaSaSo.ConsoleApp/Program.cs index 378e6fa..44cfa4f 100644 --- a/DaSaSo.ConsoleApp/Program.cs +++ b/DaSaSo.ConsoleApp/Program.cs @@ -6,7 +6,7 @@ using DaSaSo.EntityFramework; using DaSaSo.EntityFramework.Services; using System.Diagnostics; -IDataService clientService = new GenericDataService(new DaSaSoDbContextFactory()); +IDataService clientService = new GenericDataService(new DaSaSoDbContextFactory("")); clientService.Create(new Client() { Firstname = "Cynthia", diff --git a/DaSaSo.Domain/Model/Buildingsite.cs b/DaSaSo.Domain/Model/Buildingsite.cs index 3ace42d..f9edf02 100644 --- a/DaSaSo.Domain/Model/Buildingsite.cs +++ b/DaSaSo.Domain/Model/Buildingsite.cs @@ -8,6 +8,7 @@ namespace DaSaSo.Domain.Model { public class Buildingsite : DomainObject { + public Project Project { get; set; } public string BuildingSiteNumber { get; set; } public string Country { get; set; } public string ContactPerson { get; set; } diff --git a/DaSaSo.EntityFramework/DaSaSoDbContextFactory.cs b/DaSaSo.EntityFramework/DaSaSoDbContextFactory.cs index b88648f..cce0ebd 100644 --- a/DaSaSo.EntityFramework/DaSaSoDbContextFactory.cs +++ b/DaSaSo.EntityFramework/DaSaSoDbContextFactory.cs @@ -8,10 +8,14 @@ using System.Threading.Tasks; namespace DaSaSo.EntityFramework { - public class DaSaSoDbContextFactory + public class DaSaSoDbContextFactory : IDesignTimeDbContextFactory { private readonly string _connectionString; + public DaSaSoDbContextFactory() + { + + } public DaSaSoDbContextFactory(string connectionString) { _connectionString = connectionString; @@ -20,9 +24,18 @@ namespace DaSaSo.EntityFramework public DaSaSoDbContext CreateDbContext() { var options = new DbContextOptionsBuilder(); + //_connectionString = "Host = localhost; Database = dasaso; Username = kansan; Password = kansan"; options.UseNpgsql(_connectionString); DaSaSoDbContext result = new DaSaSoDbContext(options.Options); return result; } + + public DaSaSoDbContext CreateDbContext(string[]? args = null) + { + var options = new DbContextOptionsBuilder(); + options.UseNpgsql("Host = localhost; Database = dasaso; Username = kansan; Password = kansan"); + DaSaSoDbContext result = new DaSaSoDbContext(options.Options); + return result; + } } } diff --git a/DaSaSo.EntityFramework/Migrations/20210915174236_ProjectReferenzAdded.Designer.cs b/DaSaSo.EntityFramework/Migrations/20210915174236_ProjectReferenzAdded.Designer.cs new file mode 100644 index 0000000..c3f9def --- /dev/null +++ b/DaSaSo.EntityFramework/Migrations/20210915174236_ProjectReferenzAdded.Designer.cs @@ -0,0 +1,176 @@ +// +using System; +using DaSaSo.EntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace DaSaSo.EntityFramework.Migrations +{ + [DbContext(typeof(DaSaSoDbContext))] + [Migration("20210915174236_ProjectReferenzAdded")] + partial class ProjectReferenzAdded + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "6.0.0-preview.7.21378.4") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + modelBuilder.Entity("DaSaSo.Domain.Model.Buildingsite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("BuildingSiteNumber") + .HasColumnType("text"); + + b.Property("ContactPerson") + .HasColumnType("text"); + + b.Property("Country") + .HasColumnType("text"); + + b.Property("ProjectId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ProjectId"); + + b.ToTable("Buildingsites"); + }); + + modelBuilder.Entity("DaSaSo.Domain.Model.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("Country") + .HasColumnType("text"); + + b.Property("Firstname") + .HasColumnType("text"); + + b.Property("LastName") + .HasColumnType("text"); + + b.Property("Postcode") + .HasColumnType("text"); + + b.Property("Street") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("DaSaSo.Domain.Model.Project", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Projects"); + }); + + modelBuilder.Entity("DaSaSo.Domain.Model.SewerObjects", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("BuildingSiteId") + .HasColumnType("integer"); + + b.Property("DN") + .HasColumnType("integer"); + + b.Property("ObjektName") + .HasColumnType("text"); + + b.Property("PointFrom") + .HasColumnType("text"); + + b.Property("PointTo") + .HasColumnType("text"); + + b.Property("SewerLength") + .HasColumnType("numeric"); + + b.Property("StreetName") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("BuildingSiteId"); + + b.ToTable("SewerObjects"); + }); + + modelBuilder.Entity("DaSaSo.Domain.Model.Buildingsite", b => + { + b.HasOne("DaSaSo.Domain.Model.Project", "Project") + .WithMany("BuildingSites") + .HasForeignKey("ProjectId"); + + b.Navigation("Project"); + }); + + modelBuilder.Entity("DaSaSo.Domain.Model.Project", b => + { + b.HasOne("DaSaSo.Domain.Model.Client", "Client") + .WithMany("Projects") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("DaSaSo.Domain.Model.SewerObjects", b => + { + b.HasOne("DaSaSo.Domain.Model.Buildingsite", "BuildingSite") + .WithMany("SewerObjects") + .HasForeignKey("BuildingSiteId"); + + b.Navigation("BuildingSite"); + }); + + modelBuilder.Entity("DaSaSo.Domain.Model.Buildingsite", b => + { + b.Navigation("SewerObjects"); + }); + + modelBuilder.Entity("DaSaSo.Domain.Model.Client", b => + { + b.Navigation("Projects"); + }); + + modelBuilder.Entity("DaSaSo.Domain.Model.Project", b => + { + b.Navigation("BuildingSites"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DaSaSo.EntityFramework/Migrations/20210915174236_ProjectReferenzAdded.cs b/DaSaSo.EntityFramework/Migrations/20210915174236_ProjectReferenzAdded.cs new file mode 100644 index 0000000..09544e9 --- /dev/null +++ b/DaSaSo.EntityFramework/Migrations/20210915174236_ProjectReferenzAdded.cs @@ -0,0 +1,331 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DaSaSo.EntityFramework.Migrations +{ + public partial class ProjectReferenzAdded : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Projects_Clients_ClientId", + table: "Projects"); + + migrationBuilder.DropForeignKey( + name: "FK_SewerObjects_Buildingsites_BuildingSiteId", + table: "SewerObjects"); + + migrationBuilder.AlterColumn( + name: "StreetName", + table: "SewerObjects", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "PointTo", + table: "SewerObjects", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "PointFrom", + table: "SewerObjects", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "ObjektName", + table: "SewerObjects", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "BuildingSiteId", + table: "SewerObjects", + type: "integer", + nullable: true, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Projects", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "ClientId", + table: "Projects", + type: "integer", + nullable: true, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Street", + table: "Clients", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "Postcode", + table: "Clients", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "LastName", + table: "Clients", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "Firstname", + table: "Clients", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "Country", + table: "Clients", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "Country", + table: "Buildingsites", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "ContactPerson", + table: "Buildingsites", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "BuildingSiteNumber", + table: "Buildingsites", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AddForeignKey( + name: "FK_Projects_Clients_ClientId", + table: "Projects", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_SewerObjects_Buildingsites_BuildingSiteId", + table: "SewerObjects", + column: "BuildingSiteId", + principalTable: "Buildingsites", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Projects_Clients_ClientId", + table: "Projects"); + + migrationBuilder.DropForeignKey( + name: "FK_SewerObjects_Buildingsites_BuildingSiteId", + table: "SewerObjects"); + + migrationBuilder.AlterColumn( + name: "StreetName", + table: "SewerObjects", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "PointTo", + table: "SewerObjects", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "PointFrom", + table: "SewerObjects", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ObjektName", + table: "SewerObjects", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "BuildingSiteId", + table: "SewerObjects", + type: "integer", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "integer", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Projects", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ClientId", + table: "Projects", + type: "integer", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "integer", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Street", + table: "Clients", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Postcode", + table: "Clients", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "LastName", + table: "Clients", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Firstname", + table: "Clients", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Country", + table: "Clients", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Country", + table: "Buildingsites", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ContactPerson", + table: "Buildingsites", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "BuildingSiteNumber", + table: "Buildingsites", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Projects_Clients_ClientId", + table: "Projects", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_SewerObjects_Buildingsites_BuildingSiteId", + table: "SewerObjects", + column: "BuildingSiteId", + principalTable: "Buildingsites", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/DaSaSo.EntityFramework/Migrations/DaSaSoDbContextModelSnapshot.cs b/DaSaSo.EntityFramework/Migrations/DaSaSoDbContextModelSnapshot.cs index ec862a6..720b6d0 100644 --- a/DaSaSo.EntityFramework/Migrations/DaSaSoDbContextModelSnapshot.cs +++ b/DaSaSo.EntityFramework/Migrations/DaSaSoDbContextModelSnapshot.cs @@ -27,15 +27,12 @@ namespace DaSaSo.EntityFramework.Migrations .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); b.Property("BuildingSiteNumber") - .IsRequired() .HasColumnType("text"); b.Property("ContactPerson") - .IsRequired() .HasColumnType("text"); b.Property("Country") - .IsRequired() .HasColumnType("text"); b.Property("ProjectId") @@ -56,23 +53,18 @@ namespace DaSaSo.EntityFramework.Migrations .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); b.Property("Country") - .IsRequired() .HasColumnType("text"); b.Property("Firstname") - .IsRequired() .HasColumnType("text"); b.Property("LastName") - .IsRequired() .HasColumnType("text"); b.Property("Postcode") - .IsRequired() .HasColumnType("text"); b.Property("Street") - .IsRequired() .HasColumnType("text"); b.HasKey("Id"); @@ -87,11 +79,10 @@ namespace DaSaSo.EntityFramework.Migrations .HasColumnType("integer") .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - b.Property("ClientId") + b.Property("ClientId") .HasColumnType("integer"); b.Property("Name") - .IsRequired() .HasColumnType("text"); b.HasKey("Id"); @@ -108,29 +99,25 @@ namespace DaSaSo.EntityFramework.Migrations .HasColumnType("integer") .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - b.Property("BuildingSiteId") + b.Property("BuildingSiteId") .HasColumnType("integer"); b.Property("DN") .HasColumnType("integer"); b.Property("ObjektName") - .IsRequired() .HasColumnType("text"); b.Property("PointFrom") - .IsRequired() .HasColumnType("text"); b.Property("PointTo") - .IsRequired() .HasColumnType("text"); b.Property("SewerLength") .HasColumnType("numeric"); b.Property("StreetName") - .IsRequired() .HasColumnType("text"); b.HasKey("Id"); @@ -142,18 +129,18 @@ namespace DaSaSo.EntityFramework.Migrations modelBuilder.Entity("DaSaSo.Domain.Model.Buildingsite", b => { - b.HasOne("DaSaSo.Domain.Model.Project", null) + b.HasOne("DaSaSo.Domain.Model.Project", "Project") .WithMany("BuildingSites") .HasForeignKey("ProjectId"); + + b.Navigation("Project"); }); modelBuilder.Entity("DaSaSo.Domain.Model.Project", b => { b.HasOne("DaSaSo.Domain.Model.Client", "Client") .WithMany("Projects") - .HasForeignKey("ClientId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("ClientId"); b.Navigation("Client"); }); @@ -162,9 +149,7 @@ namespace DaSaSo.EntityFramework.Migrations { b.HasOne("DaSaSo.Domain.Model.Buildingsite", "BuildingSite") .WithMany("SewerObjects") - .HasForeignKey("BuildingSiteId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("BuildingSiteId"); b.Navigation("BuildingSite"); }); diff --git a/DaSaSo.EntityFramework/Services/BuildingsiteDataService.cs b/DaSaSo.EntityFramework/Services/BuildingsiteDataService.cs new file mode 100644 index 0000000..7b7ae12 --- /dev/null +++ b/DaSaSo.EntityFramework/Services/BuildingsiteDataService.cs @@ -0,0 +1,59 @@ +using DaSaSo.Domain.Model; +using DaSaSo.Domain.Services; +using DaSaSo.EntityFramework.Services.Common; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DaSaSo.EntityFramework.Services +{ + public class BuildingsiteDataService : IDataService + { + private readonly DaSaSoDbContextFactory _contextFactory; + private readonly NonQueryDataService _nonQueryDataService; + + public BuildingsiteDataService(DaSaSoDbContextFactory contextFactory) + { + _contextFactory = contextFactory; + _nonQueryDataService = new NonQueryDataService(contextFactory); + } + public async Task Create(Buildingsite entity) + { + return await _nonQueryDataService.Create(entity); + } + + public async Task Delete(int id) + { + return await _nonQueryDataService.Delete(id); + } + + public Task Get(int id) + { + throw new NotImplementedException(); + } + + public Task> GetAll() + { + throw new NotImplementedException(); + } + + public async Task> GetAllByProjekt(Project project) + { + // Get Clientid + int id = project.Id; + using (DaSaSoDbContext context = _contextFactory.CreateDbContext()) + { + IEnumerable entities = await context.Buildingsites.Where(x => x.Project.Id == id).ToListAsync(); + return entities; + } + } + + public async Task Update(int id, Buildingsite entity) + { + return await _nonQueryDataService.Update(id, entity); + } + } +} diff --git a/DaSaSo.ViewModel/BuildingsiteListViewModel.cs b/DaSaSo.ViewModel/BuildingsiteListViewModel.cs new file mode 100644 index 0000000..3fe963a --- /dev/null +++ b/DaSaSo.ViewModel/BuildingsiteListViewModel.cs @@ -0,0 +1,45 @@ +using DaSaSo.Domain.Model; +using DaSaSo.Domain.Services; +using DaSaSo.EntityFramework.Services; +using DaSaSo.ViewModel.Interface; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DaSaSo.ViewModel +{ + public class BuildingsiteListViewModel: BaseViewModel + { + public ObservableCollection Buildingsites { get; } + + private readonly IActualProject _actualProject; + private readonly IRenavigator _renavigator; + private readonly BuildingsiteDataService _buildingSiteDataService; + + public BuildingsiteListViewModel(IDataService buildingSiteDataService, IActualProject actualProject, IRenavigator renavigator) + { + _actualProject = actualProject; + _renavigator = renavigator; + _buildingSiteDataService = buildingSiteDataService as BuildingsiteDataService; + Buildingsites = new ObservableCollection(); + + LoadBuildingsites(); + } + + private async void LoadBuildingsites() + { + var buildingsites = await _buildingSiteDataService.GetAllByProjekt(_actualProject.AktuellProjekt); + InitCollection(Buildingsites, buildingsites); + } + + private void InitCollection(ObservableCollection target, IEnumerable source) + { + target.Clear(); + foreach (var i in source) + target.Add(i); + } + } +} diff --git a/DaSaSo.ViewModel/Commands/SelectProjectCommand.cs b/DaSaSo.ViewModel/Commands/SelectProjectCommand.cs new file mode 100644 index 0000000..90d73c4 --- /dev/null +++ b/DaSaSo.ViewModel/Commands/SelectProjectCommand.cs @@ -0,0 +1,27 @@ +using DaSaSo.ViewModel.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DaSaSo.ViewModel.Commands +{ + public class SelectProjectCommand : AsyncCommandBase + { + private readonly IActualProject _actualProject; + private readonly ProjectListViewModel _projectListViewModel; + + public SelectProjectCommand(IActualProject actualProject, ProjectListViewModel projectListViewModel) + { + _actualProject = actualProject; + _projectListViewModel = projectListViewModel; + } + + public override async Task ExecuteAsync(object? parameter) + { + var s = _projectListViewModel.SelectedProject; + _actualProject.SetProject(s); + } + } +} diff --git a/DaSaSo.ViewModel/Factories/ViewModelAbstractFactory.cs b/DaSaSo.ViewModel/Factories/ViewModelAbstractFactory.cs index f4945c2..8eef0e3 100644 --- a/DaSaSo.ViewModel/Factories/ViewModelAbstractFactory.cs +++ b/DaSaSo.ViewModel/Factories/ViewModelAbstractFactory.cs @@ -17,18 +17,20 @@ namespace DaSaSo.ViewModel.Factories private CreateViewModel _createClientListViewModel; private CreateViewModel _createClientEditViewModel; private CreateViewModel _createProjektListViewModel; + private CreateViewModel _createBuildingsiteListViewModel; public ViewModelAbstractFactory( CreateViewModel createHomeViewModel, CreateViewModel createClientListViewModel, CreateViewModel createClientEditViewModel, - CreateViewModel createProjektListViewModel - ) + CreateViewModel createProjektListViewModel, + CreateViewModel createBuildingsiteListViewModel) { _createHomeViewModel = createHomeViewModel; _createClientListViewModel = createClientListViewModel; _createClientEditViewModel = createClientEditViewModel; _createProjektListViewModel = createProjektListViewModel; + _createBuildingsiteListViewModel = createBuildingsiteListViewModel; } public BaseViewModel CreateViewModel(EViewType viewType) @@ -44,9 +46,9 @@ namespace DaSaSo.ViewModel.Factories return _createClientEditViewModel(); case EViewType.Projects: return _createProjektListViewModel(); - /*case EViewType.Buildingsites: - break; - case EViewType.SewerObjects: + case EViewType.Buildingsites: + return _createBuildingsiteListViewModel(); + /*case EViewType.SewerObjects: break; */ default: diff --git a/DaSaSo.ViewModel/ProjectListViewModel.cs b/DaSaSo.ViewModel/ProjectListViewModel.cs index 39ac930..6381062 100644 --- a/DaSaSo.ViewModel/ProjectListViewModel.cs +++ b/DaSaSo.ViewModel/ProjectListViewModel.cs @@ -1,6 +1,7 @@ using DaSaSo.Domain.Model; using DaSaSo.Domain.Services; using DaSaSo.EntityFramework.Services; +using DaSaSo.ViewModel.Commands; using DaSaSo.ViewModel.Interface; using System; using System.Collections.Generic; @@ -9,6 +10,7 @@ using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; namespace DaSaSo.ViewModel { @@ -19,15 +21,31 @@ namespace DaSaSo.ViewModel private IActualProject actualProject; private IRenavigator renavigator; public ObservableCollection Projekte { get; } + private Project? _selectedProject; + public Project SelectedProject + { + get => _selectedProject; + set + { + if(_selectedProject != value) + { + _selectedProject = value; + OnPropertyChanged(); + } + } + } + public ICommand SelectCommand { get; set; } public ProjectListViewModel(IDataService genericDataService, IActualProject actualProject, IRenavigator renavigator) { Projekte = new ObservableCollection(); + if (genericDataService == null) throw new ArgumentNullException("genericDataService"); this.genericDataService = (genericDataService as ProjectDataService); this.actualProject = actualProject; this.renavigator = renavigator; + SelectCommand = new SelectProjectCommand(actualProject, this); LoadProjecte(); } diff --git a/DaSaSo.Wpf/App.xaml.cs b/DaSaSo.Wpf/App.xaml.cs index 8aead5a..9d11d9b 100644 --- a/DaSaSo.Wpf/App.xaml.cs +++ b/DaSaSo.Wpf/App.xaml.cs @@ -42,6 +42,7 @@ namespace DaSaSo.Wpf services.AddSingleton(new DaSaSoDbContextFactory(connectionString)); services.AddSingleton, ClientDataService>(); services.AddSingleton, ProjectDataService>(); + services.AddSingleton, BuildingsiteDataService>(); services.AddSingleton(); @@ -79,6 +80,15 @@ namespace DaSaSo.Wpf services.GetRequiredService())); }); + services.AddSingleton>(services => + { + return () => new BuildingsiteListViewModel( + services.GetRequiredService>(), + services.GetRequiredService(), + new ViewModelDelegateRenavigator( + services.GetRequiredService())); + }); + //services.AddSingleton(); services.AddScoped(); services.AddScoped(); diff --git a/DaSaSo.Wpf/DaSaSo.Wpf.csproj.user b/DaSaSo.Wpf/DaSaSo.Wpf.csproj.user index 6832663..483d867 100644 --- a/DaSaSo.Wpf/DaSaSo.Wpf.csproj.user +++ b/DaSaSo.Wpf/DaSaSo.Wpf.csproj.user @@ -10,6 +10,9 @@ Code + + Code + Code @@ -33,6 +36,9 @@ Designer + + Designer + Designer diff --git a/DaSaSo.Wpf/View/Buildingsites/BuildingSiteListView.xaml b/DaSaSo.Wpf/View/Buildingsites/BuildingSiteListView.xaml new file mode 100644 index 0000000..1580023 --- /dev/null +++ b/DaSaSo.Wpf/View/Buildingsites/BuildingSiteListView.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/DaSaSo.Wpf/View/Buildingsites/BuildingSiteListView.xaml.cs b/DaSaSo.Wpf/View/Buildingsites/BuildingSiteListView.xaml.cs new file mode 100644 index 0000000..5a8fd00 --- /dev/null +++ b/DaSaSo.Wpf/View/Buildingsites/BuildingSiteListView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DaSaSo.Wpf.View.Buildingsites +{ + /// + /// Interaction logic for BuildingSiteListView.xaml + /// + public partial class BuildingSiteListView : UserControl + { + public BuildingSiteListView() + { + InitializeComponent(); + } + } +} diff --git a/DaSaSo.Wpf/View/Project/ProjectListView.xaml b/DaSaSo.Wpf/View/Project/ProjectListView.xaml index 60d1e30..2ceb5ae 100644 --- a/DaSaSo.Wpf/View/Project/ProjectListView.xaml +++ b/DaSaSo.Wpf/View/Project/ProjectListView.xaml @@ -7,8 +7,12 @@ mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> - - - + + + + +