diff options
Diffstat (limited to 'Gestor.Application/ViewModels/Ferramentas/SocioViewModel.cs')
| -rw-r--r-- | Gestor.Application/ViewModels/Ferramentas/SocioViewModel.cs | 358 |
1 files changed, 0 insertions, 358 deletions
diff --git a/Gestor.Application/ViewModels/Ferramentas/SocioViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/SocioViewModel.cs deleted file mode 100644 index d946d89..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/SocioViewModel.cs +++ /dev/null @@ -1,358 +0,0 @@ -using Gestor.Application.Servicos.Ferramentas;
-using Gestor.Application.Servicos.Generic;
-using Gestor.Application.ViewModels.Generic;
-using Gestor.Common.Validation;
-using Gestor.Model.Common;
-using Gestor.Model.Domain.Common;
-using Gestor.Model.Domain.Generic;
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Diagnostics;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Threading.Tasks;
-
-namespace Gestor.Application.ViewModels.Ferramentas
-{
- public class SocioViewModel : BaseSegurosViewModel
- {
- private readonly SocioServico _servico;
-
- public Socio CancelSocio;
-
- private ObservableCollection<Empresa> _empresas = new ObservableCollection<Empresa>();
-
- private Empresa _selectedEmpresa;
-
- private Socio _selectedSocio = new Socio();
-
- private ObservableCollection<Socio> _sociosFiltradas = new ObservableCollection<Socio>();
-
- private bool _isExpanded;
-
- private bool _isLoading;
-
- public ObservableCollection<Empresa> Empresas
- {
- get
- {
- return this._empresas;
- }
- set
- {
- this._empresas = value;
- base.OnPropertyChanged("Empresas");
- }
- }
-
- public bool IsExpanded
- {
- get
- {
- return this._isExpanded;
- }
- set
- {
- this._isExpanded = value;
- base.OnPropertyChanged("IsExpanded");
- }
- }
-
- public bool IsLoading
- {
- get
- {
- return this._isLoading;
- }
- set
- {
- this._isLoading = value;
- base.OnPropertyChanged("IsLoading");
- }
- }
-
- public Empresa SelectedEmpresa
- {
- get
- {
- return this._selectedEmpresa;
- }
- set
- {
- this._selectedEmpresa = value;
- this.WorkOnSelectedEmpresa(value);
- base.OnPropertyChanged("SelectedEmpresa");
- }
- }
-
- public Socio SelectedSocio
- {
- get
- {
- return this._selectedSocio;
- }
- set
- {
- long? nullable;
- this._selectedSocio = value;
- this.WorkOnSelectedSocio(value, true);
- if (value != null)
- {
- nullable = new long?(value.get_Id());
- }
- else
- {
- nullable = null;
- }
- base.VerificarEnables(nullable);
- base.OnPropertyChanged("SelectedSocio");
- }
- }
-
- public List<Socio> Socios
- {
- get;
- set;
- }
-
- public ObservableCollection<Socio> SociosFiltradas
- {
- get
- {
- return this._sociosFiltradas;
- }
- set
- {
- this._sociosFiltradas = value;
- this.IsExpanded = (value != null ? value.Count > 0 : false);
- base.OnPropertyChanged("SociosFiltradas");
- }
- }
-
- public SocioViewModel()
- {
- this._servico = new SocioServico();
- base.EnableMenu = true;
- this.Seleciona();
- }
-
- public void CancelarAlteracao()
- {
- if (this.CancelSocio == null || !this.Socios.Any<Socio>((Socio x) => x.get_Id() == this.CancelSocio.get_Id()))
- {
- this.Incluir();
- }
- else
- {
- DomainBase.Copy<Socio, Socio>(this.Socios.First<Socio>((Socio x) => x.get_Id() == this.CancelSocio.get_Id()), this.CancelSocio);
- if (this.SociosFiltradas.Count <= 0 || !this.SociosFiltradas.Any<Socio>((Socio x) => x.get_Id() == this.CancelSocio.get_Id()))
- {
- this.SociosFiltradas.Add(this.CancelSocio);
- }
- else
- {
- DomainBase.Copy<Socio, Socio>(this.SociosFiltradas.First<Socio>((Socio x) => x.get_Id() == this.CancelSocio.get_Id()), this.CancelSocio);
- }
- this.SociosFiltradas = new ObservableCollection<Socio>(this.SociosFiltradas);
- this.SelectedSocio = this.SociosFiltradas.First<Socio>((Socio x) => x.get_Id() == this.CancelSocio.get_Id());
- }
- base.Alterar(false);
- }
-
- public async void Excluir()
- {
- Socio socio;
- if (this.SelectedSocio != null && this.SelectedSocio.get_Id() != 0)
- {
- if (await base.ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO", false))
- {
- base.Loading(true);
- this.IsLoading = true;
- if (await this._servico.Delete(this.SelectedSocio))
- {
- string str = string.Concat("EXCLUIU SÓCIO \"", this.SelectedSocio.get_Nome(), "\"");
- long id = this.SelectedSocio.get_Id();
- TipoTela? nullable = new TipoTela?(19);
- object[] objArray = new object[] { this.SelectedSocio.get_Id(), this.SelectedSocio.get_Prefixo(), this.SelectedSocio.get_Telefone(), this.SelectedSocio.get_Email() };
- base.RegistrarAcao(str, id, nullable, string.Format("ID: {0}\nTELEFONE: ({1}) {2}\nE-MAIL: {3}", objArray));
- int num = this.SociosFiltradas.IndexOf(this.SelectedSocio);
- this.Socios.Remove(this.SelectedSocio);
- this.SociosFiltradas.Remove(this.SelectedSocio);
- this.SociosFiltradas = new ObservableCollection<Socio>(this.SociosFiltradas);
- if (this.SociosFiltradas.Count <= 0)
- {
- this.SelectedSocio = new Socio();
- base.Alterar(false);
- }
- else
- {
- SocioViewModel socioViewModel = this;
- socio = (num < this.SociosFiltradas.Count ? this.SociosFiltradas.ElementAt<Socio>(num) : this.SociosFiltradas.Last<Socio>());
- socioViewModel.SelectedSocio = socio;
- }
- base.Loading(false);
- this.IsLoading = false;
- base.ToggleSnackBar("SÓCIO EXCLUÍDO COM SUCESSO", true);
- }
- else
- {
- base.Loading(false);
- this.IsLoading = false;
- }
- }
- }
- }
-
- internal async Task<List<Socio>> Filtrar(string value)
- {
- List<Socio> socios = await Task.Run<List<Socio>>(() => this.FiltrarSocio(value));
- return socios;
- }
-
- public List<Socio> FiltrarSocio(string filter)
- {
- this.SociosFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Socio>(this.Socios) : new ObservableCollection<Socio>(
- from x in this.Socios
- where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter))
- orderby x.get_Nome()
- select x));
- return this.SociosFiltradas.ToList<Socio>();
- }
-
- public void Incluir()
- {
- Socio socio = new Socio();
- socio.set_IdEmpresa(this.SelectedEmpresa.get_Id());
- this.SelectedSocio = socio;
- base.Alterar(true);
- }
-
- public async Task<List<KeyValuePair<string, string>>> Salvar()
- {
- List<KeyValuePair<string, string>> keyValuePairs;
- string str;
- string str1;
- List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedSocio.Validate();
- if (keyValuePairs1.Count <= 0)
- {
- str = (this.SelectedSocio.get_Id() == 0 ? "INCLUIU" : "ALTEROU");
- str1 = str;
- Socio socio = await this._servico.Save(this.SelectedSocio);
- if (this._servico.Sucesso)
- {
- string str2 = string.Concat(str1, " SÓCIO \"", socio.get_Nome(), "\"");
- long id = socio.get_Id();
- TipoTela? nullable = new TipoTela?(19);
- object[] objArray = new object[] { socio.get_Id(), socio.get_Prefixo(), socio.get_Telefone(), socio.get_Email() };
- base.RegistrarAcao(str2, id, nullable, string.Format("ID: {0}\nTELEFONE: ({1}) {2}\nE-MAIL: {3}", objArray));
- if (!this.Socios.Any<Socio>((Socio x) => x.get_Id() == socio.get_Id()))
- {
- this.Socios.Add(socio);
- }
- else
- {
- DomainBase.Copy<Socio, Socio>(this.Socios.First<Socio>((Socio x) => x.get_Id() == socio.get_Id()), socio);
- }
- if (!this.SociosFiltradas.Any<Socio>((Socio x) => x.get_Id() == socio.get_Id()))
- {
- this.SociosFiltradas.Add(socio);
- }
- else
- {
- DomainBase.Copy<Socio, Socio>(this.SociosFiltradas.First<Socio>((Socio x) => x.get_Id() == socio.get_Id()), socio);
- }
- this.SociosFiltradas = new ObservableCollection<Socio>(this.SociosFiltradas);
- this.WorkOnSelectedSocio(socio, false);
- base.Alterar(false);
- base.ToggleSnackBar("SÓCIO SALVO COM SUCESSO", true);
- keyValuePairs = null;
- }
- else
- {
- keyValuePairs = null;
- }
- }
- else
- {
- keyValuePairs = keyValuePairs1;
- }
- str1 = null;
- return keyValuePairs;
- }
-
- private async void Seleciona()
- {
- base.Loading(true);
- await base.PermissaoTela(19);
- this.Empresas = new ObservableCollection<Empresa>(await (new EmpresaServico()).BuscarEmpresas());
- base.Loading(false);
- this.SelectedEmpresa = this.Empresas.FirstOrDefault<Empresa>();
- }
-
- private async Task SelecionaSocios(long? id)
- {
- this.Socios = null;
- this.SociosFiltradas = null;
- if (id.HasValue)
- {
- long? nullable = id;
- long num = (long)0;
- if (!(nullable.GetValueOrDefault() == num & nullable.HasValue))
- {
- base.Loading(true);
- List<Socio> socios = await (new BaseServico()).BuscarSociosAsync(id.Value);
- SocioViewModel list = this;
- List<Socio> socios1 = socios;
- list.Socios = (
- from x in socios1
- orderby x.get_Nome()
- select x).ToList<Socio>();
- this.SociosFiltradas = new ObservableCollection<Socio>(this.Socios);
- this.SelectedSocio = this.SociosFiltradas.FirstOrDefault<Socio>();
- base.Loading(false);
- return;
- }
- }
- }
-
- private async void WorkOnSelectedEmpresa(Empresa value)
- {
- if (value != null && value.get_Id() != 0)
- {
- await this.SelecionaSocios(new long?(value.get_Id()));
- }
- }
-
- private void WorkOnSelectedSocio(Socio value, bool registrar = true)
- {
- long? nullable;
- this.CancelSocio = (value == null || value.get_Id() == 0 ? this.CancelSocio : (Socio)value.Clone());
- if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 19)
- {
- return;
- }
- if (registrar)
- {
- base.RegistrarAcao(string.Concat("ACESSOU SÓCIO \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(19), string.Format("ID: {0}\nTELEFONE: ({1}) {2}\nE-MAIL: {3}", new object[] { value.get_Id(), value.get_Prefixo(), value.get_Telefone(), value.get_Email() }));
- }
- this.LastAccessId = value.get_Id();
- this.LastAccessTela = 19;
- Socio selectedSocio = this.SelectedSocio;
- if (selectedSocio != null)
- {
- nullable = new long?(selectedSocio.get_Id());
- }
- else
- {
- nullable = null;
- }
- long? nullable1 = nullable;
- long id = value.get_Id();
- if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue)
- {
- this.SelectedSocio = this.SociosFiltradas.FirstOrDefault<Socio>((Socio x) => x.get_Id() == value.get_Id());
- }
- }
- }
-}
\ No newline at end of file |