예제 #1
0
        static RestfulAPI CreateProductAsync(String url, InfoMail mailInfo)
        {
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            RestfulAPI rs  = new RestfulAPI();
            var        res = client.PostAsJsonAsync(url, mailInfo).Result;

            if (res.StatusCode == System.Net.HttpStatusCode.OK)
            {
                rs = res.Content.ReadAsAsync <RestfulAPI>().Result;
                //DataUserLogin.MaTaiKhoan = res.Content.ReadAsAsync<string>().Result;

                //if (DataUserLogin.MaTaiKhoan.Equals("-1"))
                //{
                //    MessageBox.Show("Mật khẩu hoặc tên đăng nhập không đúng!");
                //}
                //else
                //{
                //    Form1 frm = new Form1();
                //    this.Hide();
                //    frm.ShowDialog();

                //    this.Dispose();
                //}
            }
            else
            {
                MessageBox.Show("Có lỗi xảy ra!");
            }
            return(rs);
        }
예제 #2
0
        public async Task <ActionResult> Register(ActivarCuentaViewModel activarCuentaViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            ApplicationDbContext db = new ApplicationDbContext();
            var userManager         = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
            var roleManager         = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db));
            var user = userManager.Find(activarCuentaViewModel.Email, activarCuentaViewModel.PasswordTmp);

            if (user != null)
            {
                user.EmailConfirmed = true;
                await userManager.UpdateAsync(user);

                await userManager.RemovePasswordAsync(user.Id);

                await userManager.AddPasswordAsync(user.Id, activarCuentaViewModel.Password);

                string htmlData = InfoMail.CuentaActivada();
                EnviarCorreo.Enviar(user.Email, Mensaje.CuentaActivada, htmlData);
                return(RedirectToAction("Login", "Account"));
            }
            ViewBag.Tipo  = 2;
            ViewBag.Error = Mensaje.UsuarioContrasenaIncorrecto;
            return(View());
        }
예제 #3
0
        public async Task <ActionResult> RecuperarContrasena(RecuperarContrasenaRequest recuperarContrasenaRequest)
        {
            var usuario = await UserManager.FindByEmailAsync(recuperarContrasenaRequest.Email);

            if (usuario != null)
            {
                //var contrasenaTmp = GenerarCodigo.Generar(CuotasCodigos.CuotaInferiorCodigo, CuotasCodigos.CuotaSuperiorCodigo);
                await UserManager.RemovePasswordAsync(usuario.Id);

                await UserManager.AddPasswordAsync(usuario.Id, usuario.Identificacion);

                usuario.EmailConfirmed = false;
                await UserManager.UpdateAsync(usuario);

                string htmlData = InfoMail.RecuperarContrasena();
                htmlData = htmlData.Replace("@NombreUsuario", usuario.UserName);
                htmlData = htmlData.Replace("@Contrasena", usuario.Identificacion);
                //Send email
                EnviarCorreo.Enviar(usuario.Email, Mensaje.RecuperarContrasena, htmlData);

                return(View("RecuperarContrasenaInformacion"));
            }
            ModelState.AddModelError("Email", "El correo electrónico no está registrado");
            return(View());
        }
예제 #4
0
        public async Task <ActionResult> ReenviarCorreo(string id)
        {
            try
            {
                ApplicationDbContext db = new ApplicationDbContext();
                var userManager         = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
                var user          = userManager.FindById(id);
                var contrasenaTmp = GenerarCodigo.Generar(CuotasCodigos.CuotaInferiorCodigo, CuotasCodigos.CuotaSuperiorCodigo);
                await userManager.RemovePasswordAsync(user.Id);

                await userManager.AddPasswordAsync(user.Id, Convert.ToString(contrasenaTmp));

                user.EmailConfirmed = false;
                await userManager.UpdateAsync(user);

                string htmlData = InfoMail.CreacionCuentaTrabajador();
                //Send email
                EnviarCorreo.Enviar(user.Email, Mensaje.CreacionCuentaTrabajador, "<b> " + Mensaje.ContrasenaTemporal + Convert.ToString(contrasenaTmp) + "</b><br/><br/><br/>" + htmlData);
                db.Dispose();
            }
            catch (Exception)
            {
                throw;
            }

            return(RedirectToAction("ListarTrabajador"));
        }
예제 #5
0
        public ActionResult NuevoTrabajador(ApplicationUser applicationUser)
        {
            try
            {
                ApplicationDbContext db = new ApplicationDbContext();
                var userManager         = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
                var roleManager         = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db));

                var user = userManager.FindByName(applicationUser.Email);
                if (user != null)
                {
                    ViewBag.IdCiudad = new SelectList(db.Ciudades.OrderBy(x => x.Nombre), "IdCiudad", "Nombre", applicationUser.IdCiudad);
                    ModelState.AddModelError("Email", Mensaje.ExisteCorreo);
                    return(View(applicationUser));
                }

                applicationUser.UserName       = applicationUser.Email;
                applicationUser.Estado         = UsuarioEstado.Activo;
                applicationUser.EmailConfirmed = false;
                // var contrasenaTmp= GenerarCodigo.Generar(CuotasCodigos.CuotaInferiorCodigo, CuotasCodigos.CuotaSuperiorCodigo);
                userManager.Create(applicationUser, applicationUser.Identificacion);
                userManager.AddToRole(applicationUser.Id, RolUsuario.Trabajador);

                string htmlData = InfoMail.CreacionCuentaTrabajador();
                //Send email
                EnviarCorreo.Enviar(applicationUser.Email, Mensaje.CreacionCuentaTrabajador, "<b> " + Mensaje.ContrasenaTemporal + "</b><br/><br/><br/>" + htmlData);
                db.Dispose();
            }
            catch (Exception)
            {
                throw;
            }

            return(RedirectToAction("ListarTrabajador"));
        }
예제 #6
0
        public async Task <ActionResult> Eliminar(string id)
        {
            try
            {
                ApplicationDbContext db = new ApplicationDbContext();
                var userManager         = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
                var roleManager         = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db));
                var user = userManager.FindById(id);
                user.Estado = UsuarioEstado.Inactivo;
                var rol     = user.Roles.FirstOrDefault();
                var rolName = await roleManager.FindByIdAsync(rol.RoleId);

                await userManager.RemoveFromRoleAsync(user.Id, rolName.Name);

                await userManager.DeleteAsync(user);

                string htmlData = InfoMail.CuentaEliminada();
                //Send email
                EnviarCorreo.Enviar(user.Email, Mensaje.CuentaEliminada, htmlData);
                db.Dispose();
            }
            catch (Exception)
            {
                throw;
            }

            return(RedirectToAction("ListarTrabajador"));
        }
예제 #7
0
        public async Task <ActionResult> InsertarAccion(AccionesViewModel accionView)
        {
            try
            {
                if (ModelState.IsValid)
                {
                }
                ApplicationDbContext db = new ApplicationDbContext();

                var accionProceso = new Accion {
                    DetalleFin = "SIN FINALIZAR", FechaFin = DateTime.Now, Estado = EstadoAcciones.EnProceso, Detalle = accionView.Detalle, FechaInicio = accionView.FechaInicio, IdProceso = accionView.Proceso.IdProceso, IdTipoAccion = accionView.IdTipoAccion
                };

                db.Acciones.Add(accionProceso);
                await db.SaveChangesAsync();

                var    proceso  = db.Procesos.Where(x => x.IdProceso == accionView.Proceso.IdProceso).FirstOrDefault();
                var    usuario  = db.Users.Where(x => x.Id == proceso.Id).FirstOrDefault();
                string htmlData = InfoMail.CreacionAccion();

                var tipoActividad = db.TipoAcciones.Where(x => x.IdTipoAccion == accionView.IdTipoAccion).FirstOrDefault();
                htmlData = htmlData.Replace("@FechaCracion", accionView.FechaInicio.ToLongDateString());
                htmlData = htmlData.Replace("@NIP", proceso.NIP);
                htmlData = htmlData.Replace("@TipoActividad", tipoActividad.Nombre);
                htmlData = htmlData.Replace("@Detalle", accionView.Detalle);
                //Send email
                EnviarCorreo.Enviar(usuario.Email, "Se ha creado una acción", htmlData);

                if (!string.IsNullOrEmpty(usuario.CorreoNotificacion_1))
                {
                    EnviarCorreo.Enviar(usuario.CorreoNotificacion_1, "Se ha creado una acción", htmlData);
                }

                if (!string.IsNullOrEmpty(usuario.CorreoNotificacion_2))
                {
                    EnviarCorreo.Enviar(usuario.CorreoNotificacion_2, "Se ha creado una acción", htmlData);
                }
                if (!string.IsNullOrEmpty(usuario.CorreoNotificacion_3))
                {
                    EnviarCorreo.Enviar(usuario.CorreoNotificacion_3, "Se ha creado una acción", htmlData);
                }
                if (!string.IsNullOrEmpty(usuario.CorreoNotificacion_4))
                {
                    EnviarCorreo.Enviar(usuario.CorreoNotificacion_4, "Se ha creado una acción", htmlData);
                }

                db.Dispose();
                return(RedirectToAction("DetalleAcciones", new { id = accionProceso.IdProceso }));
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #8
0
        public ActionResult NuevoCliente(ApplicationUser applicationUser)
        {
            try
            {
                ApplicationDbContext db = new ApplicationDbContext();
                var userManager         = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
                var roleManager         = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db));

                var user = userManager.FindByName(applicationUser.Email);
                if (user != null)
                {
                    ViewBag.IdCiudad = new SelectList(db.Ciudades.OrderBy(x => x.Nombre), "IdCiudad", "Nombre", applicationUser.IdCiudad);
                    ModelState.AddModelError("Email", Mensaje.ExisteCorreo);
                    return(View(applicationUser));
                }


                applicationUser.UserName       = applicationUser.Email;
                applicationUser.Estado         = UsuarioEstado.Activo;
                applicationUser.EmailConfirmed = false;
                //var contrasenaTmp = GenerarCodigo.Generar(CuotasCodigos.CuotaInferiorCodigo, CuotasCodigos.CuotaSuperiorCodigo);
                userManager.Create(applicationUser, Convert.ToString(applicationUser.Identificacion));
                userManager.AddToRole(applicationUser.Id, RolUsuario.Cliente);

                string htmlData = InfoMail.CreacionCuentaCliente();
                htmlData = htmlData.Replace("@Identificacion", applicationUser.Identificacion);
                htmlData = htmlData.Replace("@NombresApellidos", applicationUser.Nombres + " " + applicationUser.Apellidos);
                htmlData = htmlData.Replace("@NombreUsuario", applicationUser.UserName);
                htmlData = htmlData.Replace("@Contrasena", applicationUser.Identificacion);
                //Send email
                EnviarCorreo.Enviar(applicationUser.Email, Mensaje.CreacionCuentaCliente, htmlData);

                return(RedirectToAction("DetalleProceso", "Proceso", new  { id = applicationUser.Id }));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "");
                throw;
            }
        }
예제 #9
0
        public async Task <ActionResult> Desactivar(string id)
        {
            try
            {
                ApplicationDbContext db = new ApplicationDbContext();
                var userManager         = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
                var user = userManager.FindById(id);
                user.Estado = UsuarioEstado.Inactivo;
                await userManager.UpdateAsync(user);

                string htmlData = InfoMail.DesactivacionCuentaAdministrador();
                //Send email
                EnviarCorreo.Enviar(user.Email, Mensaje.DesactivacionCuentaAdministrador, htmlData);
                db.Dispose();
            }
            catch (Exception)
            {
                throw;
            }

            return(RedirectToAction("ListarTrabajador"));
        }
예제 #10
0
        private void btn_tao_Click(object sender, EventArgs e)
        {
            InfoMail mailInfo = new InfoMail();

            mailInfo.username = txt_username.Text;
            mailInfo.email    = txt_email.Text;
            mailInfo.sdt      = txt_sdt.Text;
            mailInfo.cmnd     = txt_cmnd.Text;
            mailInfo.ngaysinh = dtp_ngaysinh.Value.ToString("yyyyMMdd");
            mailInfo.diachi   = txt_diachi.Text;
            if (cbb_loaiuser.Text.Equals("Sinh Viên"))
            {
                mailInfo.loaiUS = 1;
            }
            else if (cbb_loaiuser.Text.Equals("Giáo Viên"))
            {
                mailInfo.loaiUS = 2;
            }
            else
            {
                mailInfo.loaiUS = 3;
            }
            mailInfo.password_email = txt_passemail.Text;

            String     url = localhost + "rest/mail/dangkimail";
            RestfulAPI rs  = CreateProductAsync(url, mailInfo);

            if (rs.ketqua == 1)
            {
                MessageBox.Show("Thành công !");
            }
            else
            {
                MessageBox.Show("Có lỗi xảy ra!");
            }
        }
예제 #11
0
        public async Task <ActionResult> DetalleProceso(ProcesoViewModel procesoView)
        {
            ApplicationDbContext db = new ApplicationDbContext();

            if (!ModelState.IsValid)
            {
                var user = UserManager.FindById(procesoView.Id);
                ViewBag.Identificacion = $"{user.Identificacion}";
                ViewBag.NombreApellido = $"{user.Nombres + "  " + user.Apellidos}";
                ViewBag.PhoneNumber    = $"{user.PhoneNumber}";
                ViewBag.Email          = $"{user.Email}";

                ViewBag.IdentificacionConyuge  = $"{user.IdentificacionConyuge}";
                ViewBag.NombreApellidoConyugue = $"{user.NombresConyuge + "  " + user.ApellidosConyuge}";
                ViewBag.CorreoConyuge          = $"{user.CorreoConyuge}";
                ViewBag.TelefonoConyuge        = $"{user.TelefonoConyuge}";

                ViewBag.CorreoNotificacion_1 = $"{user.CorreoNotificacion_1}";
                ViewBag.CorreoNotificacion_2 = $"{user.CorreoNotificacion_2}";
                ViewBag.CorreoNotificacion_3 = $"{user.CorreoNotificacion_3}";
                ViewBag.CorreoNotificacion_4 = $"{user.CorreoNotificacion_4}";


                var listaProcesos = db.Procesos.Where(x => x.Id == procesoView.Id).OrderByDescending(x => x.FechaInicio).ToList();
                ViewBag.TotalProcesos = listaProcesos.Count();
                var procesoViewModel = new ProcesoViewModel {
                    Id = procesoView.Id, ListaProcesos = listaProcesos, Detalle = procesoView.Detalle, FechaInicio = procesoView.FechaInicio
                };
                return(View(procesoViewModel));
            }


            var existeNIP = db.Procesos.Where(x => x.NIP == procesoView.NIP).FirstOrDefault();


            if (existeNIP != null)
            {
                ModelState.AddModelError("NIP", "El NIP ya está asignado otro proceso, por favor intente con otro NIP");
                var user = UserManager.FindById(procesoView.Id);
                ViewBag.Identificacion = $"{user.Identificacion}";
                ViewBag.NombreApellido = $"{user.Nombres + "  " + user.Apellidos}";
                ViewBag.PhoneNumber    = $"{user.PhoneNumber}";
                ViewBag.Email          = $"{user.Email}";

                ViewBag.IdentificacionConyuge  = $"{user.IdentificacionConyuge}";
                ViewBag.NombreApellidoConyugue = $"{user.NombresConyuge + "  " + user.ApellidosConyuge}";
                ViewBag.CorreoConyuge          = $"{user.CorreoConyuge}";
                ViewBag.TelefonoConyuge        = $"{user.TelefonoConyuge}";

                ViewBag.CorreoNotificacion_1 = $"{user.CorreoNotificacion_1}";
                ViewBag.CorreoNotificacion_2 = $"{user.CorreoNotificacion_2}";
                ViewBag.CorreoNotificacion_3 = $"{user.CorreoNotificacion_3}";
                ViewBag.CorreoNotificacion_4 = $"{user.CorreoNotificacion_4}";

                var listaProcesos = db.Procesos.Where(x => x.Id == procesoView.Id).OrderByDescending(x => x.FechaInicio).ToList();
                ViewBag.TotalProcesos = listaProcesos.Count();
                var procesoViewModel = new ProcesoViewModel {
                    Id = procesoView.Id, ListaProcesos = listaProcesos, Detalle = procesoView.Detalle, FechaInicio = procesoView.FechaInicio
                };
                return(View(procesoViewModel));
            }
            var proceso = new Proceso {
                Id = procesoView.Id, Detalle = procesoView.Detalle, FechaInicio = procesoView.FechaInicio, NIP = procesoView.NIP
            };

            db.Procesos.Add(proceso);

            await db.SaveChangesAsync();

            var    usuario  = db.Users.Where(x => x.Id == procesoView.Id).FirstOrDefault();
            string htmlData = InfoMail.CreacionProceso();

            htmlData = htmlData.Replace("@FechaCracion", procesoView.FechaInicio.ToLongDateString());
            htmlData = htmlData.Replace("@NIP", procesoView.NIP);
            htmlData = htmlData.Replace("@Detalle", procesoView.Detalle);
            //Send email
            EnviarCorreo.Enviar(usuario.Email, "Se ha creado un proceso", htmlData);

            if (!string.IsNullOrEmpty(usuario.CorreoNotificacion_1))
            {
                EnviarCorreo.Enviar(usuario.CorreoNotificacion_1, "Se ha creado un proceso", htmlData);
            }

            if (!string.IsNullOrEmpty(usuario.CorreoNotificacion_2))
            {
                EnviarCorreo.Enviar(usuario.CorreoNotificacion_2, "Se ha creado un proceso", htmlData);
            }
            if (!string.IsNullOrEmpty(usuario.CorreoNotificacion_3))
            {
                EnviarCorreo.Enviar(usuario.CorreoNotificacion_3, "Se ha creado un proceso", htmlData);
            }
            if (!string.IsNullOrEmpty(usuario.CorreoNotificacion_4))
            {
                EnviarCorreo.Enviar(usuario.CorreoNotificacion_4, "Se ha creado un proceso", htmlData);
            }

            return(RedirectToAction("DetalleProceso", new { id = procesoView.Id }));
        }