Ejemplo n.º 1
0
        public JsonResult GuardarAsunto(dtoAsuntos Asunto)
        {
            if (!Request.IsAuthenticated)
            {
                return(Json(new { ErrorInterno = "No se ha podido autenticar al usuario" }));
            }
            CultureInfo Cultura = CultureInfo.CreateSpecificCulture("es-MX");

            Thread.CurrentThread.CurrentCulture = Cultura;
            Asunto.Asunto = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Asunto.Asunto);
            ApplicationUser Usuario = UserManager.FindById(User.Identity.GetUserId());
            string          RawData = String.Format("{0}_{1}", Usuario.UserName, Asunto.Asunto.Trim());
            string          Hash    = EmailService.ComputarSha256(RawData);

            Asunto.HashAsunto = Hash;
            Asunto.Email      = Usuario.UserName;
            Tuple <bool, string> _result = new BALAsuntos().UpdateAsuntos(Asunto);

            if (!_result.Item1)
            {
                return(Json(new { Exito = false, Mensaje = ConstantesComunes.ERROR_GENERICO }));
            }
            else
            {
                var Servicio = new EmailService();
                Servicio.sendMailAsunto(Asunto.Asunto.Trim(), new dtoPersonas {
                    Email = Usuario.UserName
                });
                return(Json(new { Exito = true, Mensaje = ConstantesComunes.EXITOWEB_GENERIO + ConstantesAsuntos.VERIFICAR_ASUNTO }));
            }
        }
Ejemplo n.º 2
0
        public FileResult DownloadArchivoAsunto(string Guid)
        {
            List <dtoAsuntos> _result = new BALAsuntos().GetAsuntosArchivos(new dtoAsuntos {
                Email = User.Identity.GetUserName()
            }, false, Guid);

            if (_result != null)
            {
                dtoAsuntos _resultado = _result.FirstOrDefault();
                string     extension  = _resultado.NombreArchivo.Substring(_resultado.NombreArchivo.LastIndexOf("."), _resultado.NombreArchivo.Length - _resultado.NombreArchivo.LastIndexOf("."));
                return(File(_result.FirstOrDefault().Archivo, extension.ToLower() == ".pdf" ? System.Net.Mime.MediaTypeNames.Application.Pdf : System.Net.Mime.MediaTypeNames.Application.Pdf, _resultado.NombreArchivo));
            }
            return(null);
        }
Ejemplo n.º 3
0
        public JsonResult VerificaAsunto(dtoAsuntos Asunto)
        {
            List <dtoAsuntos> _result = new BALAsuntos().GetAsuntosArchivos(new dtoAsuntos {
                Email = User.Identity.GetUserName()
            }, true);

            if (_result != null)
            {
                CultureInfo Cultura = CultureInfo.CreateSpecificCulture("es-MX");
                Thread.CurrentThread.CurrentCulture = Cultura;
                Asunto.Asunto = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Asunto.Asunto);
                dtoAsuntos _resultado = _result.FirstOrDefault(k => k.Asunto == Asunto.Asunto);
                return(Json(new { Exito = _resultado == null }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { Exito = false }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
        public ActionResult GetAsuntosPorUsuario()
        {
            List <dtoAsuntos> model   = new List <dtoAsuntos>();
            List <dtoAsuntos> _result = new BALAsuntos().GetAsuntosArchivos(new dtoAsuntos {
                Email = User.Identity.GetUserName()
            }, false);

            if (_result == null)
            {
                _result = new List <dtoAsuntos>();
            }
            Session["ArchivosCargados"] = _result.Where(x => !String.IsNullOrEmpty(x.GuidArchivo)).ToList();
            var Agrupados = _result.GroupBy(x => x.IdAsunto);

            foreach (var Asunto in Agrupados)
            {
                model.Add(_result.FirstOrDefault(k => k.IdAsunto == Asunto.Key));
            }
            ViewBag.Archivos = Session["ArchivosCargados"];
            List <SelectListItem> ComboAsuntos = new List <SelectListItem> {
                new SelectListItem {
                    Selected = true,
                    Text     = "Seleccione",
                    Value    = "0"
                }
            };

            model = model.Select(x =>
            {
                ComboAsuntos.Add(new SelectListItem
                {
                    Selected = false,
                    Value    = x.IdAsunto.ToString(),
                    Text     = x.Asunto
                });
                return(x);
            }).ToList();
            ViewBag.ComboAsuntos = ComboAsuntos;
            return(PartialView(model));
        }
Ejemplo n.º 5
0
        public ActionResult UploadLocal(dtoAsuntos Asuntos, HttpFileCollection archivos_locales)
        {
            string IdUsuario = User.Identity.GetUserId();
            HttpFileCollectionBase Archivos = Request.Files;

            if (Archivos != null)
            {
                List <dtoAsuntos> Listado = new List <dtoAsuntos>();
                for (int i = 0; i < Archivos.Count; i++)
                {
                    HttpPostedFileBase file   = Request.Files[i];
                    dtoAsuntos         Asunto = new dtoAsuntos
                    {
                        IdUsuario     = IdUsuario,
                        Archivo       = new byte[file.ContentLength],
                        IdAsunto      = Asuntos.IdAsunto,
                        NombreArchivo = file.FileName,
                        Drive         = false,
                    };
                    file.InputStream.Read(Asunto.Archivo, 0, file.ContentLength);
                    string destPath = Path.Combine(Server.MapPath("~/App_Data"), file.FileName);
                    System.IO.File.Create(destPath);
                    Listado.Add(Asunto);
                }
                Tuple <bool, string> Upload = new BALAsuntos().UpdateArchivosAsuntos(Listado);
                if (Upload.Item1)
                {
                    Session["ArchivosDownloadDrive"] = true;
                }
                else
                {
                    Session["ArchivosDownloadDrive"] = false;
                }
            }
            return(RedirectToAction("MisAsuntos"));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> DownloadFileDrive(string code)
        {
            List <dtoAsuntos> Archivos = (List <dtoAsuntos>)Session["ArchivosDownloadDrive"];

            try
            {
                string        IdUsuario   = User.Identity.GetUserId();
                string        redirectUrl = $"https://{Request.Url.Host}:{Request.Url.Port}/{Url.Action(nameof(this.DownloadFileDrive)).TrimStart('/')}";
                string        path        = Server.MapPath("~/client_secrets.json");
                ClientSecrets Secrets     = null;
                using (var filestream = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    Secrets = GoogleClientSecrets.Load(filestream).Secrets;
                }
                var initializer = new GoogleAuthorizationCodeFlow.Initializer()
                {
                    ClientSecrets = Secrets,
                    Scopes        = Scopes,
                };
                int UserIdPersona = 0;


                var googleCodeFlow = new GoogleAuthorizationCodeFlow(initializer);
                var token          = googleCodeFlow.ExchangeCodeForTokenAsync(UserIdPersona != 0 ? UserIdPersona.ToString() : Session["IdUsuario"].ToString(), code, redirectUrl, CancellationToken.None).Result;
                //var resultMVC = new AuthorizationCodeWebApp(googleCodeFlow, redirectUrl, redirectUrl).AuthorizeAsync(UserId.ToString(), CancellationToken.None).Result;
                UserCredential credential = new UserCredential(googleCodeFlow, UserIdPersona != 0 ? UserIdPersona.ToString() : Session["IdUsuario"].ToString(), token);
                DriveService   service    = new DriveService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = Application_Name,
                    ApiKey = "AIzaSyBtEx9nIXbv-C-jEj45iIUZvs-HUP8SCc8"
                });
                foreach (dtoAsuntos FileId in Archivos)
                {
                    FilesResource.GetRequest request = service.Files.Get(FileId.GuidArchivo);

                    string destPath = Path.Combine(Server.MapPath("~/App_Data"), FileId.NombreArchivo);
                    using (FileStream filestream = new FileStream(destPath, FileMode.Create, FileAccess.Write))
                    {
                        request.MediaDownloader.ProgressChanged +=
                            (IDownloadProgress progress) =>
                        {
                            switch (progress.Status)
                            {
                            case DownloadStatus.Downloading:
                            {
                                Debug.WriteLine(progress.BytesDownloaded);
                                break;
                            }

                            case DownloadStatus.Completed:
                            {
                                Debug.WriteLine("Download complete.");
                                break;
                            }

                            case DownloadStatus.Failed:
                            {
                                Debug.WriteLine("Download failed.");
                                break;
                            }
                            }
                        };
                        await request.DownloadAsync(filestream);
                    }
                    byte[] Blob = System.IO.File.ReadAllBytes(destPath);
                    FileId.Archivo     = Blob;
                    FileId.GuidArchivo = String.Empty;
                    FileId.IdUsuario   = IdUsuario;
                }
                Tuple <bool, string> _result = new BALAsuntos().UpdateArchivosAsuntos(Archivos);

                foreach (dtoAsuntos file in Archivos)
                {
                    string destPath = Path.Combine(Server.MapPath("~/App_Data"), file.NombreArchivo);
                    System.IO.File.Delete(destPath);
                }

                Session["ArchivosDownloadDrive"] = null;
                if (_result.Item1)
                {
                    Session["ArchivosDownloadDrive"] = true;
                }
            }
            catch (Exception ex)
            {
            }
            return(RedirectToAction("MisAsuntos"));
        }