diff options
Diffstat (limited to 'Gestor.Application/ViewModels/Ferramentas/RamoViewModel.cs')
| -rw-r--r-- | Gestor.Application/ViewModels/Ferramentas/RamoViewModel.cs | 332 |
1 files changed, 0 insertions, 332 deletions
diff --git a/Gestor.Application/ViewModels/Ferramentas/RamoViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/RamoViewModel.cs deleted file mode 100644 index 09ab1ea..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/RamoViewModel.cs +++ /dev/null @@ -1,332 +0,0 @@ -using Gestor.Application.Helpers;
-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.Generic;
-using Gestor.Model.Domain.Seguros;
-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 RamoViewModel : BaseSegurosViewModel
- {
- private readonly RamoServico _servico;
-
- private Ramo _selectedRamo = new Ramo();
-
- private decimal _iof;
-
- private ObservableCollection<Ramo> _ramosFiltrados = new ObservableCollection<Ramo>();
-
- private bool _isExpanded;
-
- private List<CoberturaPadrao> _coberturas = new List<CoberturaPadrao>();
-
- private ObservableCollection<CoberturaPadrao> _coberturasFiltradas = new ObservableCollection<CoberturaPadrao>();
-
- public Ramo CancelRamo;
-
- public List<CoberturaPadrao> Coberturas
- {
- get
- {
- return this._coberturas;
- }
- set
- {
- this._coberturas = value;
- base.OnPropertyChanged("Coberturas");
- }
- }
-
- public ObservableCollection<CoberturaPadrao> CoberturasFiltradas
- {
- get
- {
- return this._coberturasFiltradas;
- }
- set
- {
- this._coberturasFiltradas = value;
- base.OnPropertyChanged("CoberturasFiltradas");
- }
- }
-
- public decimal Iof
- {
- get
- {
- return this._iof;
- }
- set
- {
- this._iof = value;
- base.OnPropertyChanged("Iof");
- }
- }
-
- public bool IsExpanded
- {
- get
- {
- return this._isExpanded;
- }
- set
- {
- this._isExpanded = value;
- base.OnPropertyChanged("IsExpanded");
- }
- }
-
- public List<Ramo> Ramos
- {
- get;
- set;
- }
-
- public ObservableCollection<Ramo> RamosFiltrados
- {
- get
- {
- return this._ramosFiltrados;
- }
- set
- {
- this._ramosFiltrados = value;
- this.IsExpanded = (value != null ? value.Count > 0 : false);
- base.OnPropertyChanged("RamosFiltrados");
- }
- }
-
- public Ramo SelectedRamo
- {
- get
- {
- return this._selectedRamo;
- }
- set
- {
- long? nullable;
- this._selectedRamo = value;
- this.WorkOnSelectedRamo(value, true);
- if (value != null)
- {
- nullable = new long?(value.get_Id());
- }
- else
- {
- nullable = null;
- }
- base.VerificarEnables(nullable);
- base.OnPropertyChanged("SelectedRamo");
- }
- }
-
- public RamoViewModel()
- {
- this._servico = new RamoServico();
- base.EnableMenu = true;
- this.Seleciona();
- }
-
- public void CancelarAlteracao()
- {
- if (this.CancelRamo != null && this.Ramos.Any<Ramo>((Ramo x) => x.get_Id() == this.CancelRamo.get_Id()))
- {
- DomainBase.Copy<Ramo, Ramo>(this.Ramos.First<Ramo>((Ramo x) => x.get_Id() == this.CancelRamo.get_Id()), this.CancelRamo);
- if (this.RamosFiltrados.Count <= 0 || !this.RamosFiltrados.Any<Ramo>((Ramo x) => x.get_Id() == this.CancelRamo.get_Id()))
- {
- this.RamosFiltrados.Add(this.CancelRamo);
- }
- else
- {
- DomainBase.Copy<Ramo, Ramo>(this.RamosFiltrados.First<Ramo>((Ramo x) => x.get_Id() == this.CancelRamo.get_Id()), this.CancelRamo);
- }
- this.RamosFiltrados = new ObservableCollection<Ramo>(this.RamosFiltrados);
- this.SelectedRamo = this.RamosFiltrados.First<Ramo>((Ramo x) => x.get_Id() == this.CancelRamo.get_Id());
- }
- base.Alterar(false);
- }
-
- internal async Task<List<Ramo>> Filtrar(string value)
- {
- List<Ramo> ramos = await Task.Run<List<Ramo>>(() => this.FiltrarRamo(value));
- return ramos;
- }
-
- internal async Task<List<CoberturaPadrao>> FiltrarCobertura(string value)
- {
- List<CoberturaPadrao> coberturaPadraos = await Task.Run<List<CoberturaPadrao>>(() => this.FiltrarCoberturaRamo(value));
- return coberturaPadraos;
- }
-
- public List<CoberturaPadrao> FiltrarCoberturaRamo(string filter)
- {
- this.CoberturasFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<CoberturaPadrao>(this.Coberturas) : new ObservableCollection<CoberturaPadrao>(
- from x in this.Coberturas
- where ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter))
- select x));
- return this.CoberturasFiltradas.ToList<CoberturaPadrao>();
- }
-
- public List<Ramo> FiltrarRamo(string filter)
- {
- this.RamosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Ramo>(this.Ramos) : new ObservableCollection<Ramo>(
- from x in this.Ramos
- where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter))
- orderby x.get_Ativo() descending, x.get_Nome()
- select x));
- return this.RamosFiltrados.ToList<Ramo>();
- }
-
- public async void Incluir(Ramo ramo)
- {
- ramo.set_Ativo(true);
- await this._servico.Insert(ramo);
- if (this._servico.Sucesso)
- {
- await this.SelecionaRamos(ramo);
- }
- }
-
- public async Task<List<KeyValuePair<string, string>>> Salvar()
- {
- List<KeyValuePair<string, string>> keyValuePairs;
- string str;
- string str1;
- this.SelectedRamo.set_Iof(this.Iof);
- List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedRamo.Validate();
- if (keyValuePairs1.Count <= 0)
- {
- Ramo selectedRamo = this.SelectedRamo;
- selectedRamo.set_Iof(selectedRamo.get_Iof() * new decimal(100));
- str = (this.SelectedRamo.get_Id() == 0 ? "INCLUIU" : "ALTEROU");
- str1 = str;
- Ramo ramo = await this._servico.Save(this.SelectedRamo, this.Coberturas);
- Ramo ramo1 = ramo;
- if (this._servico.Sucesso)
- {
- base.RegistrarAcao(string.Concat(str1, " RAMO \"", ramo1.get_Nome(), "\""), ramo1.get_Id(), new TipoTela?(12), string.Format("RAMO \"{0}\", ID: {1}", ramo1.get_Nome(), ramo1.get_Id()));
- if (!this.Ramos.Any<Ramo>((Ramo x) => x.get_Id() == ramo1.get_Id()))
- {
- this.Ramos.Add(ramo1);
- }
- else
- {
- DomainBase.Copy<Ramo, Ramo>(this.Ramos.First<Ramo>((Ramo x) => x.get_Id() == ramo1.get_Id()), ramo1);
- }
- if (!this.RamosFiltrados.Any<Ramo>((Ramo x) => x.get_Id() == ramo1.get_Id()))
- {
- this.RamosFiltrados.Add(ramo1);
- }
- else
- {
- DomainBase.Copy<Ramo, Ramo>(this.RamosFiltrados.First<Ramo>((Ramo x) => x.get_Id() == ramo1.get_Id()), ramo1);
- }
- this.RamosFiltrados = new ObservableCollection<Ramo>(this.RamosFiltrados);
- Recursos.Ramos = this.Ramos;
- await RamoViewModel.SelecionaCoberturas();
- this.WorkOnSelectedRamo(ramo1, false);
- base.Alterar(false);
- base.ToggleSnackBar("RAMO SALVO COM SUCESSO", true);
- keyValuePairs = null;
- }
- else
- {
- keyValuePairs = null;
- }
- }
- else
- {
- keyValuePairs = keyValuePairs1;
- }
- str1 = null;
- return keyValuePairs;
- }
-
- public async void Seleciona()
- {
- base.Loading(true);
- await base.PermissaoTela(12);
- await this.SelecionaRamos(null);
- base.Loading(false);
- }
-
- private static async Task SelecionaCoberturas()
- {
- Recursos.Coberturas = await (new BaseServico()).BuscaCoberturas();
- }
-
- public void SelecionaRamo(Ramo ramo)
- {
- this.SelectedRamo = ramo;
- }
-
- private async Task SelecionaRamos(Ramo ramo = null)
- {
- Ramo ramo1;
- base.Loading(true);
- await RamoViewModel.SelecionaCoberturas();
- List<Ramo> ramos = await (new BaseServico()).BuscarRamosAsync();
- RamoViewModel list = this;
- List<Ramo> ramos1 = ramos;
- IOrderedEnumerable<Ramo> ativo =
- from x in ramos1
- orderby x.get_Ativo() descending
- select x;
- list.Ramos = ativo.ThenBy<Ramo, string>((Ramo x) => x.get_Nome()).ToList<Ramo>();
- this.RamosFiltrados = new ObservableCollection<Ramo>(this.Ramos);
- RamoViewModel ramoViewModel = this;
- ramo1 = (ramo == null ? this.RamosFiltrados.First<Ramo>() : this.RamosFiltrados.FirstOrDefault<Ramo>((Ramo x) => x.get_Id() == ramo.get_Id()));
- ramoViewModel.SelectedRamo = ramo1;
- Recursos.Ramos = ramos;
- base.Loading(false);
- }
-
- private void WorkOnSelectedRamo(Ramo value, bool registrar = true)
- {
- long? nullable;
- this.CancelRamo = (value == null || value.get_Id() == 0 ? this.CancelRamo : (Ramo)value.Clone());
- if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 12)
- {
- return;
- }
- this.Coberturas = (
- from x in Recursos.Coberturas
- where x.get_IdRamo() == value.get_Id()
- orderby x.get_Padrao() descending, x.get_Descricao()
- select x).ToList<CoberturaPadrao>();
- this.CoberturasFiltradas = new ObservableCollection<CoberturaPadrao>(this.Coberturas);
- this.Iof = value.get_Iof() * new decimal(1, 0, 0, false, 2);
- if (registrar)
- {
- base.RegistrarAcao(string.Concat("ACESSOU RAMO \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(12), string.Format("ID RAMO: {0}", value.get_Id()));
- }
- this.LastAccessId = value.get_Id();
- this.LastAccessTela = 12;
- Ramo selectedRamo = this.SelectedRamo;
- if (selectedRamo != null)
- {
- nullable = new long?(selectedRamo.get_Id());
- }
- else
- {
- nullable = null;
- }
- long? nullable1 = nullable;
- long id = value.get_Id();
- if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue)
- {
- this.SelectedRamo = this.RamosFiltrados.FirstOrDefault<Ramo>((Ramo x) => x.get_Id() == value.get_Id());
- }
- }
- }
-}
\ No newline at end of file |