예제 #1
0
        public async Task <IActionResult> RegisterUser(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                SqlGenericManager _sqlManager = new SqlGenericManager();

                //Passa informações da Org para o novo usuário
                var user = new ApplicationUser {
                    UserName      = model.Email,
                    Email         = model.Email,
                    idOrganizacao = new Guid(model.idOrganizacao),
                    nomeAmigavel  = model.NomeAmigavel,
                    idPerfil      = new Guid(model.perfil)
                };

                //Cria o usuários
                var result = await _userManager.CreateAsync(user, model.Password);

                CargaInicial CA = new CargaInicial();
                //Cria Profissinal para cada usuário
                CA.CreateProfissional(user, this.contexto, this.dbContext);

                if (result.Succeeded)
                {
                    return(RedirectToAction("FormUpdateUsuario", "Usuario", new { id = user.Id.ToString() }));
                }
                AddErrors(result);
            }

            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                Guid idOrg = Guid.NewGuid();
                SqlGenericManager _sqlManager = new SqlGenericManager();
                SqlGeneric        _sqlService = new SqlGeneric();


                //Se for a primeira Organização criar no banco
                if (_sqlManager.ExisteOrganizacao(model.organizacao.nomeLogin, out idOrg))
                {
                    model.msgOrganizacao = "** Essa empresa já está cadastrada. ***";
                    return(View(model));
                }

                //Passa informações da Org para o novo usuário
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, idOrganizacao = idOrg, userAdmin = true
                };

                //Cria o usuários
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //Cria objeto do contexto
                    this.contexto.idOrganizacao = idOrg;
                    this.contexto.idUsuario     = new Guid(user.Id);

                    //Cria nova Organização e Inicializa valores padrões
                    _sqlService.InicializaOrg(idOrg.ToString(), model.organizacao.nomeLogin, model.Email);

                    //***************** CARGA INICIAL DA ORGANIZAÇÃO VIA OBJETO *************************
                    CargaInicial CA = new CargaInicial();

                    //Cria Perfils de acesso
                    CA.CreatePerfis(user, this.contexto, this.dbContext);

                    //Cria OrgConfig
                    CA.CreateOrgConfig(this.contexto, this.dbContext);

                    //***************** FIM CARGA INICIAL DA ORGANIZAÇÃO *************************

                    model.sucesso        = true;
                    model.msgOrganizacao = "Organização criada, Empresa:" + model.organizacao.nomeLogin + ", E-mail de acesso:" + model.Email;
                    return(View(model));
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #3
0
        public ActionResult Index()
        {
            var cargaInicial = new CargaInicial();

            //var x = new Producto();
            //x.Nombre = "Casa";
            //mProductos.Add(x);
            return(View(mProductos.Todos()));
        }
예제 #4
0
        public ContextoTeste(bool inicializaDados = false)
        {
            this.Disciplinas = new DBSetTeste <Disciplina>();
            dbSets           = new Dictionary <Type, object>();
            dbSets.Add(typeof(Disciplina), Disciplinas);

            if (inicializaDados)
            {
                CargaInicial.CarregaDados(this);
            }
        }
예제 #5
0
 public ActionResult CreateInical()
 {
     try
     {
         CargaInicial blCargaInicial = new CargaInicial();
         blCargaInicial.Inicio();
         return(Json(new { success = true }));
     }
     catch {
         return(Json(new { success = false }));
     }
 }
예제 #6
0
 protected override void Seed(ContextoEntity contexto)
 {
     CargaInicial.CarregaDados(contexto);
 }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogDebug($"tarea en segundo plano esta iniciando");
            stoppingToken.Register(() => _logger.LogDebug("Deteniendo la tarea en segundo plano"));
            var _context = _scope.ServiceProvider.GetRequiredService <ApplicationDbContext>();

            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogDebug("Ejecutando tarea en segundo plano");
                string ruta          = "";
                string nombreArchivo = "";
                /*Todo:  Revisar Findesemanas*/
                //if(DateTime.Now.DayOfWeek == DayOfWeek.Monday)
                //{
                //    nombreArchivo = "Carga" + DateTime.Now.AddDays(-3).ToString("ddMMyyyy");
                //    ruta = _configuration["RutaCargaCredito"] + nombreArchivo + ".txt";
                //}
                //else if(
                //    DateTime.Now.DayOfWeek == DayOfWeek.Thursday ||
                //    DateTime.Now.DayOfWeek == DayOfWeek.Wednesday ||
                //    DateTime.Now.DayOfWeek == DayOfWeek.Tuesday ||
                //    DateTime.Now.DayOfWeek == DayOfWeek.Friday
                //)
                //{
                //    nombreArchivo = "Carga" + DateTime.Now.AddDays(-1).ToString("ddMMyyyy");
                //    ruta = _configuration["RutaCargaCredito"] + nombreArchivo + ".txt";
                //}
                //else {
                //    break;
                //}

                nombreArchivo = "Carga17092019";
                ruta          = _configuration["RutaCargaCredito"] + nombreArchivo + ".txt";
                _logger.LogDebug(ruta);

                var existencia = _context.CargasIniciales.Where(x => x.NombreArchivoCarga == nombreArchivo).ToList();
                if ((File.Exists(ruta) && existencia.Count == 0) || (File.Exists(ruta) && File.ReadLines(ruta).Count() - 1 > existencia.Count))
                {
                    _logger.LogDebug("Cargando Archivo a la BD (Carga Inicial diaria)......");

                    int lap             = 0;
                    int emperzardenuevo = File.ReadLines(ruta).Count() - 1 > existencia.Count ? existencia.Count + 1 : 1;
                    foreach (var linea in File.ReadLines(ruta))
                    {
                        if (lap > 0 && emperzardenuevo == lap)
                        {
                            emperzardenuevo++;
                            string[] campos            = linea.Split(new char[] { ';' });
                            var      existenciaCredito = _context.CargasIniciales.FirstOrDefault(ci => ci.FolioCredito == campos[1] && ci.RutAfiliado == campos[0]);

                            if (existenciaCredito == null)
                            {
                                DateTime     ferchaCorresponde = DateTime.ParseExact(campos[10], "ddMMyyyy", CultureInfo.InvariantCulture);
                                CargaInicial ci = new CargaInicial
                                {
                                    RutAfiliado          = campos[0],
                                    FolioCredito         = campos[1],
                                    CodigoOficinaIngreso = campos[2],
                                    CodigoOficinaPago    = campos[4],
                                    Estado             = campos[6],
                                    LineaCredito       = campos[7],
                                    RutResponsable     = campos[8],
                                    CanalVenta         = campos[9],
                                    FechaVigencia      = campos[10],
                                    FechaCarga         = DateTime.Now,
                                    FechaCorresponde   = ferchaCorresponde,
                                    NombreArchivoCarga = nombreArchivo
                                };
                                _context.CargasIniciales.Add(ci);


                                var    oficinaProceso = _context.Oficinas.Include(x => x.OficinaProceso).FirstOrDefault(x => x.Codificacion == ci.CodigoOficinaPago);
                                string esRM           = oficinaProceso.EsRM  ? $"1" : $"0";

                                /*  TODO: Caso de La Unión ver con Jenny Bernales  */
                                Dictionary <string, string> _setVariables = new Dictionary <string, string>();
                                _setVariables.Add("OFICINA_PAGO", campos[4]);
                                _setVariables.Add("OFICINA_INGRESO", campos[2]);
                                _setVariables.Add("FOLIO_CREDITO", campos[1]);
                                _setVariables.Add("RUT_AFILIADO", campos[0]);
                                _setVariables.Add("FECHA_VENTA", campos[10]);
                                _setVariables.Add("ES_RM", esRM);
                                _setVariables.Add("DOCUMENTO_LEGALIZADO", $"0");
                                _setVariables.Add("OFICINA_PROCESA_NOTARIA", oficinaProceso.OficinaProceso.Codificacion);



                                _wfservice = new WorkflowService(new DefaultWorkflowKernel(_context, _configuration));
                                var wf = _wfservice.Instanciar(ProcesoDocumentos.NOMBRE_PROCESO, "wfboot", "Ingreso Automatico de Creditos Vendidos", _setVariables);

                                Credito cred = new Credito
                                {
                                    FechaDesembolso = ferchaCorresponde,
                                    FechaFormaliza  = DateTime.Now.AddDays(-1),
                                    FolioCredito    = ci.FolioCredito,
                                    MontoCredito    = 0,
                                    RutCliente      = ci.RutAfiliado,
                                    NumeroTicket    = wf.NumeroTicket
                                };

                                if (ci.LineaCredito.ToLower().Contains("credito normal") && ci.Estado.Contains("Reprogramado"))
                                {
                                    cred.TipoCredito = TipoCredito.Reprogramacion;
                                }
                                else if (ci.LineaCredito.ToLower().Contains("credito normal") || ci.LineaCredito.ToLower().Contains("compra cartera") || ci.LineaCredito.ToLower().Contains("credito paralelo"))
                                {
                                    cred.TipoCredito = TipoCredito.Normal;
                                }
                                else if (ci.LineaCredito.ToLower().Contains("reprogr"))
                                {
                                    cred.TipoCredito = TipoCredito.Reprogramacion;
                                }
                                else if (ci.LineaCredito.ToLower().Contains("acuerdo de creditos castigados"))
                                {
                                    cred.TipoCredito = TipoCredito.AcuerdoPago;
                                }



                                IEnumerable <ConfiguracionDocumento> configs = _context.ConfiguracionDocumentos.Where(x => x.TipoCredito == cred.TipoCredito && x.TipoExpediente == TipoExpediente.Legal).ToList();


                                ExpedienteCredito expcred = new ExpedienteCredito
                                {
                                    Credito        = cred,
                                    FechaCreacion  = DateTime.Now,
                                    TipoExpediente = TipoExpediente.Legal,
                                };

                                int incrementor = 1;
                                foreach (var confItem in configs)
                                {
                                    Documento docmnt = new Documento {
                                        TipoDocumento = confItem.TipoDocumento,
                                        Codificacion  = confItem.Codificacion,
                                        Resumen       = confItem.TipoDocumento.ToString("D")
                                    };
                                    expcred.Documentos.Add(docmnt);
                                    incrementor++;
                                }
                                _context.ExpedientesCreditos.Add(expcred);
                                await _context.SaveChangesAsync();
                            }
                        }
                        lap++;
                    }
                    _logger.LogDebug("Carga terminada");
                    var           destinatarios = _configuration.GetSection("CoordinacionWorkers:CargaInicialCreditosWorker:DestinatariosNotificaciones").Get <string[]>();
                    StringBuilder mailTemplate  = new StringBuilder();
                    mailTemplate.AppendLine("<p>La carga Inicial ha Terminado con éxito.</p>");
                    mailTemplate.AppendLine("<small>Correo enviado automaticamente por Galvarino favor no contestar.</small>");
                    await _mailService.SendEmail(destinatarios, $"Carga Inicial {nombreArchivo}", mailTemplate.ToString());
                }
                else
                {
                    _logger.LogDebug("Nada que cargar");
                }

                _logger.LogDebug("Esperando!!!!");
                await Task.Delay(60000, stoppingToken);
            }
        }