Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Reactive;
- using System.Reactive.Concurrency;
- using CTR.Infrastructure.Repository;
- using CTR.Models.POCO;
- using CTR.Utils;
- using ReactiveUI;
- namespace CTR.ViewModels
- {
- public class CadastroDepartamentoViewModel : ViewModelBase
- {
- public CadastroDepartamentoViewModel(IRepository repository, DispatcherScheduler uiDispatcherScheduler)
- : base(repository, uiDispatcherScheduler)
- {
- Secretarias = new ObservableCollection<Secretaria>();
- SalvarCommand = ReactiveCommand.Create(SalvarDepartamentoExecute);
- Repository.GetAll<Secretaria>()
- .Busy(this)
- .Subscribe(CarregarSecretarias);
- }
- public string Descricao { get; set; }
- public ObservableCollection<Secretaria> Secretarias { get; }
- public Secretaria SecretariaSelecionada { get; set; }
- public ReactiveCommand<Unit, Unit> SalvarCommand { get; }
- private void CarregarSecretarias(IEnumerable<Secretaria> secretarias)
- {
- foreach(var secretaria in secretarias)
- {
- Secretarias.Add(secretaria);
- }
- }
- private void SalvarDepartamentoExecute()
- {
- var dotacao = new Departamento
- {
- Descricao = Descricao,
- SecretariaId = SecretariaSelecionada.SecretariaId
- };
- Repository.Add(dotacao).Subscribe();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement