Esempio n. 1
0
        public ActionResult MisArchivosCompartidos(string id)
        {
            db.Configuration.ProxyCreationEnabled = false;
            db.Configuration.LazyLoadingEnabled   = false;

            List <Models.Aplicacion.File> archivos    = new List <Models.Aplicacion.File>();
            ApplicationUserManager        UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var usuario   = User.Identity.GetUserId();
            var resultado = db.Turnos.Where(x => x.IdTurno == id).FirstOrDefault();
            //var paciente = db.Pacientes.Where(x => x.Id == resultado.Paciente.Id).FirstOrDefault();
            //var profesional = db.Especialistas.Where(x => x.Id == resultado.Especialista.Id).FirstOrDefault();
            var rol = UserManager.GetRoles(usuario);

            if (rol.Contains("Paciente"))
            {
                var result = db.FileSharedRelacion.Include("File").Where(x => x.IdRelacion == resultado.IdTurno).FirstOrDefault();
                if (result != null)
                {
                    Models.Aplicacion.File ok = result.File;
                    ok.FullPath = ok.FullPath.Replace(@"\\", @"\");
                    return(Json(new { Url = Url.Action("ShowData", ok) }));

                    //return PartialView("~/Views/VideoConferencia/_UploadFiles.cshtml", ok);
                }
                else
                {
                    return(null);
                }
            }
            if (rol.Contains("Paciente"))
            {
                var result = db.FileSharedRelacion.Include("File").Where(x => x.IdRelacion == resultado.IdTurno).FirstOrDefault();
                Models.Aplicacion.File ok = result.File;
                ok.FullPath = ok.FullPath.Replace(@"\\", @"\");
                return(PartialView("~/Views/VideoConferencia/_UploadFiles.cshtml", result.File));
            }
            return(null);
        }
Esempio n. 2
0
        public ActionResult SubirArchivosConsulta()
        {
            bool   isSavedSuccessfully = true;
            string fName = "";
            ApplicationUserManager UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var usuario = User.Identity.GetUserId();

            if (usuario == null)
            {
                return(HttpNotFound());
            }
            try
            {
                var filefolder = string.Empty;
                var savefile   = "";
                foreach (string fileName in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[fileName];
                    fName = file.FileName;
                    string folder    = User.Identity.Name;
                    var    path      = Server.MapPath("~/Content/img/" + folder);
                    var    directory = new DirectoryInfo(path);

                    if (directory.Exists == false)
                    {
                        directory.Create();
                        savefile = Path.Combine(Server.MapPath(path), System.IO.Path.GetFileName(file.FileName));
                        file.SaveAs(savefile);
                        Models.Aplicacion.File archivo = new Models.Aplicacion.File();
                        archivo.Estado    = true;
                        archivo.Fecha     = DateTime.Now;
                        archivo.FullPath  = savefile.ToString();
                        archivo.IdUsuario = User.Identity.GetUserId();
                        db.Files.Add(archivo);
                    }
                    else
                    {
                        savefile = Path.Combine(path, System.IO.Path.GetFileName(file.FileName));
                        file.SaveAs(savefile);
                        Models.Aplicacion.File archivo = new Models.Aplicacion.File();
                        archivo.Estado    = true;
                        archivo.Fecha     = DateTime.Now;
                        archivo.FullPath  = savefile.ToString();
                        archivo.IdUsuario = User.Identity.GetUserId();
                        db.Files.Add(archivo);
                    }
                    db.SaveChanges();
                    //You can Save the file content here
                }
            } catch (Exception ex)
            {
                @ViewBag.Error = ex.Message;
            }

            if (isSavedSuccessfully)
            {
                string folder     = User.Identity.Name;
                var    path       = Server.MapPath("~/Content/img/" + folder);
                string targetPath = Path.Combine(path, fName);

                var result    = db.Files.Where(x => x.FullPath == targetPath).FirstOrDefault();
                var resultado = Json(result, JsonRequestBehavior.AllowGet);
                return(Json(new { archivo = resultado.Data }));
            }
            else
            {
                return(Json(new { Message = "Error in saving file" }));
            }
            //var attachmentlist = db.Files.ToList();

            //return Json(new { Message = fName }, JsonRequestBehavior.AllowGet);
        }