public int Add(ClienteViewModel entity) { if (m_ClienteService.FindBy(x => x.CPF.Equals(entity.Cpf)).Any()) { throw new Exception("Cpf informado ja existe."); } if (string.IsNullOrEmpty(entity.Orgaoemissor)) { throw new Exception("Favor informar orgão emissor."); } if (string.IsNullOrEmpty(entity.Ufemissor)) { throw new Exception("Favor informar uf emissor."); } if (entity.Orgaotrabalhoid <= 0) { throw new Exception("Favor informar orgão de trabalho."); } if (entity.Escolaridadeid <= 0) { throw new Exception("Favor informar escolaridade."); } //if (entity.Dtnascimento == null) throw new Exception("Favor informar data de nascimento."); if (entity.Dtemissao == null || entity.Dtemissao <= DateTime.MinValue) { entity.Dtemissao = DateTime.Now; } if (entity.Dtnascimento == null || entity.Dtnascimento < DateTime.MinValue) { entity.Dtnascimento = DateTime.Now; } var cliente = new EV_CLIENTE { USERID = entity.Userid, NOME = entity.Nome, EMAIL = entity.Email, RG = entity.Rg, ORGAOEMISSOR = entity.Orgaoemissor, UFEMISSOR = entity.Ufemissor, DTEMISSAO = entity.Dtemissao, CPF = entity.Cpf.Replace(".", "").Replace("/", "").Replace("-", ""), NACIONALIDADE = entity.Nacionalidade, NATURALIDADE = entity.Naturalidade, DTNASCIMENTO = entity.Dtnascimento, SEXO = entity.Sexo, NOMEPAI = entity.Nomepai, NOMEMAE = entity.Nomemae, CEP = entity.Cep, ENDERECO = entity.Endereco, BAIRRO = entity.Bairro, NUMERO = entity.Numero, COMPLEMENTO = entity.Complemento, CIDADE = entity.Cidade, ESTADO = entity.Estado, TEL_RESIDENCIAL = entity.Telresidencial, TEL_COMERCIAL = entity.Telcomercial, TEL_CELULAR = entity.Telcelular, SENHA = entity.Senha, CAD_ADMINISTRACAO = entity.Cadadministracao, ENVIO_SENHA = entity.Enviosenha, INSTITUICAO = entity.Instituicao, DTCONCLUSAO = entity.Dtconclusao, DTCADASTRO = DateTime.Now, DTALTERACAO = DateTime.Now, //DTULTIMOACESSO = entity.Dtultimoacesso, RECEBERFEEDS = entity.Receberfeeds, ORGAOTRABALHOID = entity.Orgaotrabalhoid, ESCOLARIDADEID = entity.Escolaridadeid }; //using (var transaction = new System.Transactions.TransactionScope()) //{ var user = new ApplicationUser { UserName = entity.Cpf, Email = entity.Email }; var result = UserManager.CreateAsync(user, entity.Senha).Result; if (!result.Succeeded) { var erros = string.Empty; foreach (var item in result.Errors) { erros += item.ToString() + " "; } if (erros.Contains("is already taken") && erros.Contains("Email")) { erros = erros.Replace("is already taken", "já existe"); } if (erros == "Passwords must have at least one non letter or digit character. Passwords must have at least one uppercase ('A'-'Z').") { erros = "As senhas devem ter pelo menos um caractere não letra ou dígito. As senhas devem ter pelo menos uma maiúscula('A' - 'Z')."; } throw new Exception(string.Format("Ocorreu um erro ao cadastrar o cliente: {0}", erros)); } var userIdentity = UserManager.FindByNameAsync(entity.Cpf).Result; cliente.USERID = userIdentity.Id; if (entity.Idantigo != 0) { cliente.IDANTIGO = entity.Idantigo; } if (entity.Qtdacesso != 0) { cliente.QTDACESSO = entity.Qtdacesso; } m_ClienteService.Add(cliente); var comit = m_ClienteService.Commit(); //transaction.Complete(); return(comit); //} }
private ClienteViewModel ConvertToClienteViewModel(EV_CLIENTE item) { var clienteViewModel = new ClienteViewModel { Id = item.ID, Nome = item.NOME, Email = item.EMAIL, Rg = item.RG, Orgaoemissor = item.ORGAOEMISSOR, Ufemissor = item.UFEMISSOR, Dtemissao = item.DTEMISSAO, Cpf = item.CPF, Nacionalidade = item.NACIONALIDADE, Naturalidade = item.NATURALIDADE, Dtnascimento = item.DTNASCIMENTO ?? DateTime.Now, Sexo = item.SEXO, Nomepai = item.NOMEPAI, Nomemae = item.NOMEMAE, Cep = item.CEP, Endereco = item.ENDERECO, Bairro = item.BAIRRO, Numero = item.NUMERO ?? 0, Complemento = item.COMPLEMENTO, Cidade = item.CIDADE, Estado = item.ESTADO, Telresidencial = item.TEL_RESIDENCIAL, Telcomercial = item.TEL_COMERCIAL, Telcelular = item.TEL_CELULAR, Senha = item.SENHA, Cadadministracao = item.CAD_ADMINISTRACAO, Enviosenha = item.ENVIO_SENHA, Orgaotrabalhoid = item.ORGAOTRABALHOID ?? 0, Escolaridadeid = item.ESCOLARIDADEID ?? 0, Instituicao = item.INSTITUICAO, Dtconclusao = item.DTCONCLUSAO ?? DateTime.Now, Dtalteracao = item.DTALTERACAO ?? DateTime.Now, Dtultimoacesso = item.DTULTIMOACESSO ?? DateTime.Now, Idantigo = item.IDANTIGO ?? 0, Idorgaoantigo = item.IDORGAOANTIGO ?? 0, Idescolaridadeantigo = item.IDESCOLARIDADEANTIGO ?? 0, Qtdacesso = item.QTDACESSO ?? 0, Receberfeeds = item.RECEBERFEEDS ?? 0, }; if (item.AD_ORGAOS != null) { clienteViewModel.OrgaoTrabalho = item.AD_ORGAOS.ORGAO; } else { clienteViewModel.OrgaoTrabalho = "Sem Informação"; } if (item.EV_INSCRICAO != null) { if (item.EV_INSCRICAO.Count > 0) { clienteViewModel.Inscricoes = item.EV_INSCRICAO.Select(insc => new InscricaoViewModel { Baixa = insc.BAIXA, Boletoemitido = insc.BOLETOEMITIDO, Clienteid = insc.CLIENTEID, Criado = insc.CRIADO ?? DateTime.Now, Datapagamento = insc.DATAPAGAMENTO ?? DateTime.Now, Dtboletoemitido = insc.DTBOLETOEMITIDO ?? DateTime.Now, Dtinscricao = insc.DTINSCRICAO, Formapagamento = insc.FORMAPAGAMENTO, Id = item.ID, Pago = insc.PAGO, Turno = insc.TURNO, Valor = insc.VALOR, Valorrecebido = insc.VALORRECEBIDO ?? 0, NomeCliente = item.NOME, Evento = m_EventoService.GetById(insc.EVENTOID).NOME, Dtalteracao = insc.DTALTERACAO, Dtcadastro = insc.DTCADASTRO, Dtexclusao = insc.DTEXCLUSAO, Dtpagamento = insc.DATAPAGAMENTO.HasValue ? insc.DATAPAGAMENTO.Value.ToString("dd/MM/yyyy") : "Sem informação" }); } else { clienteViewModel.Inscricoes = new List <InscricaoViewModel>(); } } return(clienteViewModel); }
/// <summary> /// Delete Entity EV_CLIENTE /// </summary> /// <param name="entity"></param> public void Delete(EV_CLIENTE entity) { UnitOfWork.ClienteRepository.Delete(entity); }
/// <summary> /// Update Entity EV_CLIENTE /// </summary> /// <param name="entity"></param> public void Update(EV_CLIENTE entity) { UnitOfWork.ClienteRepository.Edit(entity); }
/// <summary> /// Add Entity EV_CLIENTE /// </summary> /// <param name="entity"></param> public void Add(EV_CLIENTE entity) { UnitOfWork.ClienteRepository.Add(entity); }