Buildingsite list hinzugefügt

This commit is contained in:
HuskyTeufel
2021-09-15 20:06:55 +02:00
parent e0c9839275
commit 4123cc7aba
18 changed files with 754 additions and 33 deletions

View File

@@ -6,7 +6,7 @@ using DaSaSo.EntityFramework;
using DaSaSo.EntityFramework.Services;
using System.Diagnostics;
IDataService<Client> clientService = new GenericDataService<Client>(new DaSaSoDbContextFactory());
IDataService<Client> clientService = new GenericDataService<Client>(new DaSaSoDbContextFactory(""));
clientService.Create(new Client()
{
Firstname = "Cynthia",

View File

@@ -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; }

View File

@@ -8,10 +8,14 @@ using System.Threading.Tasks;
namespace DaSaSo.EntityFramework
{
public class DaSaSoDbContextFactory
public class DaSaSoDbContextFactory : IDesignTimeDbContextFactory<DaSaSoDbContext>
{
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<DaSaSoDbContext>();
//_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<DaSaSoDbContext>();
options.UseNpgsql("Host = localhost; Database = dasaso; Username = kansan; Password = kansan");
DaSaSoDbContext result = new DaSaSoDbContext(options.Options);
return result;
}
}
}

View File

@@ -0,0 +1,176 @@
// <auto-generated />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("BuildingSiteNumber")
.HasColumnType("text");
b.Property<string>("ContactPerson")
.HasColumnType("text");
b.Property<string>("Country")
.HasColumnType("text");
b.Property<int?>("ProjectId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ProjectId");
b.ToTable("Buildingsites");
});
modelBuilder.Entity("DaSaSo.Domain.Model.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Country")
.HasColumnType("text");
b.Property<string>("Firstname")
.HasColumnType("text");
b.Property<string>("LastName")
.HasColumnType("text");
b.Property<string>("Postcode")
.HasColumnType("text");
b.Property<string>("Street")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("DaSaSo.Domain.Model.Project", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int?>("ClientId")
.HasColumnType("integer");
b.Property<string>("Name")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Projects");
});
modelBuilder.Entity("DaSaSo.Domain.Model.SewerObjects", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int?>("BuildingSiteId")
.HasColumnType("integer");
b.Property<int>("DN")
.HasColumnType("integer");
b.Property<string>("ObjektName")
.HasColumnType("text");
b.Property<string>("PointFrom")
.HasColumnType("text");
b.Property<string>("PointTo")
.HasColumnType("text");
b.Property<decimal>("SewerLength")
.HasColumnType("numeric");
b.Property<string>("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
}
}
}

View File

@@ -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<string>(
name: "StreetName",
table: "SewerObjects",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "PointTo",
table: "SewerObjects",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "PointFrom",
table: "SewerObjects",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "ObjektName",
table: "SewerObjects",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<int>(
name: "BuildingSiteId",
table: "SewerObjects",
type: "integer",
nullable: true,
oldClrType: typeof(int),
oldType: "integer");
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Projects",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<int>(
name: "ClientId",
table: "Projects",
type: "integer",
nullable: true,
oldClrType: typeof(int),
oldType: "integer");
migrationBuilder.AlterColumn<string>(
name: "Street",
table: "Clients",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "Postcode",
table: "Clients",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "LastName",
table: "Clients",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "Firstname",
table: "Clients",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "Country",
table: "Clients",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "Country",
table: "Buildingsites",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "ContactPerson",
table: "Buildingsites",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
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<string>(
name: "StreetName",
table: "SewerObjects",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "PointTo",
table: "SewerObjects",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "PointFrom",
table: "SewerObjects",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "ObjektName",
table: "SewerObjects",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "BuildingSiteId",
table: "SewerObjects",
type: "integer",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "integer",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Projects",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "ClientId",
table: "Projects",
type: "integer",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "integer",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Street",
table: "Clients",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Postcode",
table: "Clients",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "LastName",
table: "Clients",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Firstname",
table: "Clients",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Country",
table: "Clients",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Country",
table: "Buildingsites",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "ContactPerson",
table: "Buildingsites",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
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);
}
}
}

View File

@@ -27,15 +27,12 @@ namespace DaSaSo.EntityFramework.Migrations
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("BuildingSiteNumber")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ContactPerson")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Country")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("ProjectId")
@@ -56,23 +53,18 @@ namespace DaSaSo.EntityFramework.Migrations
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Country")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Firstname")
.IsRequired()
.HasColumnType("text");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Postcode")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Street")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
@@ -87,11 +79,10 @@ namespace DaSaSo.EntityFramework.Migrations
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("ClientId")
b.Property<int?>("ClientId")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
@@ -108,29 +99,25 @@ namespace DaSaSo.EntityFramework.Migrations
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("BuildingSiteId")
b.Property<int?>("BuildingSiteId")
.HasColumnType("integer");
b.Property<int>("DN")
.HasColumnType("integer");
b.Property<string>("ObjektName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PointFrom")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PointTo")
.IsRequired()
.HasColumnType("text");
b.Property<decimal>("SewerLength")
.HasColumnType("numeric");
b.Property<string>("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");
});

View File

@@ -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<Buildingsite>
{
private readonly DaSaSoDbContextFactory _contextFactory;
private readonly NonQueryDataService<Buildingsite> _nonQueryDataService;
public BuildingsiteDataService(DaSaSoDbContextFactory contextFactory)
{
_contextFactory = contextFactory;
_nonQueryDataService = new NonQueryDataService<Buildingsite>(contextFactory);
}
public async Task<Buildingsite> Create(Buildingsite entity)
{
return await _nonQueryDataService.Create(entity);
}
public async Task<bool> Delete(int id)
{
return await _nonQueryDataService.Delete(id);
}
public Task<Buildingsite> Get(int id)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Buildingsite>> GetAll()
{
throw new NotImplementedException();
}
public async Task<IEnumerable<Buildingsite>> GetAllByProjekt(Project project)
{
// Get Clientid
int id = project.Id;
using (DaSaSoDbContext context = _contextFactory.CreateDbContext())
{
IEnumerable<Buildingsite> entities = await context.Buildingsites.Where(x => x.Project.Id == id).ToListAsync();
return entities;
}
}
public async Task<Buildingsite> Update(int id, Buildingsite entity)
{
return await _nonQueryDataService.Update(id, entity);
}
}
}

View File

@@ -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<Buildingsite> Buildingsites { get; }
private readonly IActualProject _actualProject;
private readonly IRenavigator _renavigator;
private readonly BuildingsiteDataService _buildingSiteDataService;
public BuildingsiteListViewModel(IDataService<Buildingsite> buildingSiteDataService, IActualProject actualProject, IRenavigator renavigator)
{
_actualProject = actualProject;
_renavigator = renavigator;
_buildingSiteDataService = buildingSiteDataService as BuildingsiteDataService;
Buildingsites = new ObservableCollection<Buildingsite>();
LoadBuildingsites();
}
private async void LoadBuildingsites()
{
var buildingsites = await _buildingSiteDataService.GetAllByProjekt(_actualProject.AktuellProjekt);
InitCollection(Buildingsites, buildingsites);
}
private void InitCollection(ObservableCollection<Buildingsite> target, IEnumerable<Buildingsite> source)
{
target.Clear();
foreach (var i in source)
target.Add(i);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -17,18 +17,20 @@ namespace DaSaSo.ViewModel.Factories
private CreateViewModel<ClientListViewModel> _createClientListViewModel;
private CreateViewModel<ClientEditViewModel> _createClientEditViewModel;
private CreateViewModel<ProjectListViewModel> _createProjektListViewModel;
private CreateViewModel<BuildingsiteListViewModel> _createBuildingsiteListViewModel;
public ViewModelAbstractFactory(
CreateViewModel<HomeViewModel> createHomeViewModel,
CreateViewModel<ClientListViewModel> createClientListViewModel,
CreateViewModel<ClientEditViewModel> createClientEditViewModel,
CreateViewModel<ProjectListViewModel> createProjektListViewModel
)
CreateViewModel<ProjectListViewModel> createProjektListViewModel,
CreateViewModel<BuildingsiteListViewModel> 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:

View File

@@ -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<Project> 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<Project> genericDataService, IActualProject actualProject, IRenavigator renavigator)
{
Projekte = new ObservableCollection<Project>();
if (genericDataService == null) throw new ArgumentNullException("genericDataService");
this.genericDataService = (genericDataService as ProjectDataService);
this.actualProject = actualProject;
this.renavigator = renavigator;
SelectCommand = new SelectProjectCommand(actualProject, this);
LoadProjecte();
}

View File

@@ -42,6 +42,7 @@ namespace DaSaSo.Wpf
services.AddSingleton<DaSaSoDbContextFactory>(new DaSaSoDbContextFactory(connectionString));
services.AddSingleton<IDataService<Client>, ClientDataService>();
services.AddSingleton<IDataService<Project>, ProjectDataService>();
services.AddSingleton<IDataService<Buildingsite>, BuildingsiteDataService>();
services.AddSingleton<ClientListViewModel>();
@@ -79,6 +80,15 @@ namespace DaSaSo.Wpf
services.GetRequiredService<INavigator>()));
});
services.AddSingleton<CreateViewModel<BuildingsiteListViewModel>>(services =>
{
return () => new BuildingsiteListViewModel(
services.GetRequiredService<IDataService<Buildingsite>>(),
services.GetRequiredService<IActualProject>(),
new ViewModelDelegateRenavigator(
services.GetRequiredService<INavigator>()));
});
//services.AddSingleton<INavigator, Navigator>();
services.AddScoped<IActualProject, ActualProject>();
services.AddScoped<INavigator, Navigator>();

View File

@@ -10,6 +10,9 @@
<Compile Update="Controls\NavigationBar.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="View\Buildingsites\BuildingSiteListView.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="View\Client\ClientEditView.xaml.cs">
<SubType>Code</SubType>
</Compile>
@@ -33,6 +36,9 @@
<Page Update="Styles\Navigation_Style.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="View\Buildingsites\BuildingSiteListView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="View\Client\ClientEditView.xaml">
<SubType>Designer</SubType>
</Page>

View File

@@ -0,0 +1,12 @@
<UserControl x:Class="DaSaSo.Wpf.View.Buildingsites.BuildingSiteListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DaSaSo.Wpf.View.Buildingsites"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<DataGrid ItemsSource="{Binding Buildingsites}" />
</Grid>
</UserControl>

View File

@@ -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
{
/// <summary>
/// Interaction logic for BuildingSiteListView.xaml
/// </summary>
public partial class BuildingSiteListView : UserControl
{
public BuildingSiteListView()
{
InitializeComponent();
}
}
}

View File

@@ -7,8 +7,12 @@
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<DataGrid ItemsSource="{Binding Projekte}">
<StackPanel>
<DataGrid IsReadOnly="True" ItemsSource="{Binding Projekte}" SelectedItem="{Binding SelectedProject}">
</DataGrid>
<Button Content="Selektiere" Command="{Binding SelectCommand}" />
</StackPanel>
</Grid>
</UserControl>

View File

@@ -5,6 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ClientViews="clr-namespace:DaSaSo.Wpf.View.Client"
xmlns:ProjektViews="clr-namespace:DaSaSo.Wpf.View.Project"
xmlns:BuildingsiteViews="clr-namespace:DaSaSo.Wpf.View.Buildingsites"
xmlns:controls="clr-namespace:DaSaSo.Wpf.Controls"
xmlns:View="clr-namespace:DaSaSo.Wpf.View"
xmlns:local="clr-namespace:DaSaSo.Wpf" xmlns:viewmodel="clr-namespace:DaSaSo.ViewModel;assembly=DaSaSo.ViewModel" d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}"
@@ -23,6 +24,9 @@
<DataTemplate DataType="{x:Type viewmodel:HomeViewModel}">
<View:HomeView />
</DataTemplate>
<DataTemplate DataType="{x:Type viewmodel:BuildingsiteListViewModel}">
<BuildingsiteViews:BuildingSiteListView />
</DataTemplate>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>

View File

@@ -1,5 +1,5 @@
{
"ConnectionStrings": {
"default": "Host = localhoste; Database = dasaso; Username = kansan; Password = kansan"
"default": "Host = localhost; Database = dasaso; Username = kansan; Password = kansan"
}
}