119 lines
3.1 KiB
C#
119 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using DevExpress.Mvvm;
|
|
|
|
namespace BeWo.ViewModel.ListViewModel
|
|
{
|
|
public class WohneinheitListVM : AbstractListVM<WohneinheitDC, WohneinheitVM>
|
|
{
|
|
public DelegateCommand AddChildVMCommand { get; set; }
|
|
|
|
public bool PermissionWohneinheitButton => PermissionWohneinheitManage || PermissionWohneinheitGalleryView;
|
|
|
|
public bool PermissionWohneinheitManage { get; } = BeWoApp.HasLoggedOnUserRight(UserRightType.WohnheimView_Wohneinheit_Manage);
|
|
|
|
public bool PermissionWohneinheitGalleryView { get; } = BeWoApp.HasLoggedOnUserRight(UserRightType.WohnheimView_Wohneinheit_Gallery_View);
|
|
|
|
/// <summary>
|
|
/// Designer
|
|
/// </summary>
|
|
public WohneinheitListVM() : base(null)
|
|
{
|
|
VMList.Add(new WohneinheitVM());
|
|
}
|
|
|
|
public WohneinheitListVM(List<WohneinheitDC> pDCs) : base(pDCs)
|
|
{
|
|
AddVMCommand = new DelegateCommand(Add, () => PermissionWohneinheitManage);
|
|
|
|
AddChildVMCommand = new DelegateCommand(AddChild, CanManageAndSelectedIsObject);
|
|
|
|
DeleteSelectedVMCommand = new DelegateCommand(DeleteSelected, () => PermissionWohneinheitManage);
|
|
}
|
|
|
|
public override bool IsDirty => base.IsDirty;
|
|
|
|
public void Add()
|
|
{
|
|
AddNewVMToListAndSelect(true);
|
|
}
|
|
|
|
public void AddChild()
|
|
{
|
|
var parent = SelectedVM;
|
|
|
|
AddNewVMToListAndSelect(true);
|
|
|
|
SelectedVM.Wohnname = parent.Wohnname;
|
|
SelectedVM.Baujahr = parent.Baujahr;
|
|
SelectedVM.Stock = parent.Stock;
|
|
}
|
|
|
|
public void DeleteSelected()
|
|
{
|
|
var selected_vm = SelectedVM;
|
|
|
|
if (selected_vm is null)
|
|
return;
|
|
|
|
var displayname = selected_vm.Displayname2;
|
|
|
|
var suc = DeleteSelectedVM($"Wohneinheit '{displayname}'");
|
|
|
|
if (suc && VMList.Any())
|
|
SelectedVM = VMList.Last();
|
|
}
|
|
|
|
public bool SelectNewWohneinheit()
|
|
{
|
|
SelectedVM = NewVM;
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool SelectNewChildWohneinheit(WohneinheitVM parent)
|
|
{
|
|
SelectedVM = NewVM;
|
|
|
|
SelectedVM.Wohnname = parent.Wohnname;
|
|
SelectedVM.Baujahr = parent.Baujahr;
|
|
SelectedVM.Stock = parent.Stock;
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool EditWohneinheit(WohneinheitVM vm)
|
|
{
|
|
if (vm is null || !VMList.Contains(vm))
|
|
return false;
|
|
|
|
EditVM = vm;
|
|
SelectedVM = vm;
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool CanManageAndSelectedIsObject()
|
|
{
|
|
return PermissionWohneinheitManage && SelectedVM != null;
|
|
}
|
|
|
|
public void CloseNewVM()
|
|
{
|
|
NewVM = null;
|
|
SelectedVM = null;
|
|
}
|
|
|
|
public void CloseEditVM()
|
|
{
|
|
EditVM = null;
|
|
SelectedVM = null;
|
|
}
|
|
}
|
|
} |