49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using KanSan.Base;
|
|
using KanSan.Base.Interfaces;
|
|
using KanSan.Base.Interfaces.UI;
|
|
using KanSan.Base.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace KanSan.ViewModel
|
|
{
|
|
public class BaustellenListViewModel : IBaustelleListViewModel
|
|
{
|
|
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
|
|
private List<Baustelle> baustellen;
|
|
private Projekt selectedProjekt;
|
|
|
|
public List<Baustelle> Baustellen
|
|
{
|
|
get
|
|
{
|
|
return baustellen;
|
|
}
|
|
}
|
|
|
|
public BaustellenListViewModel(Projekt projekt)
|
|
{
|
|
selectedProjekt = projekt;
|
|
baustellen = unitOfWork.BaustelleRepository.Get(x => x.Projekt.Equals(projekt)).ToList();
|
|
}
|
|
|
|
public Baustelle NeueBaustelle()
|
|
{
|
|
Guid guid = Guid.NewGuid();
|
|
Baustelle newBaustelle = new Baustelle()
|
|
{
|
|
GuidNr = guid,
|
|
Projekt = selectedProjekt
|
|
};
|
|
unitOfWork.BaustelleRepository.Update(newBaustelle);
|
|
unitOfWork.Commit();
|
|
List<Baustelle> res = unitOfWork.BaustelleRepository.Get(x => x.GuidNr.Equals(guid)).ToList();
|
|
if (res.Count < 1) throw new Exception("Der zuvor eingefügte Baustelle konnte nicht gefunden werden");
|
|
return res.First();
|
|
}
|
|
|
|
}
|
|
}
|