Exemplo n.º 1
1
        public ContentResult CreateFileUsingName(string fileName)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(ctx));
                var currentUser = manager.FindById(User.Identity.GetUserId());
                var fileManager = new FileManager(manager.FindById(User.Identity.GetUserId()).Id);

                    var entity = new File
                    {
                        Nom = fileName,
                        DateCreation = DateTime.Now,
                        NombreObjets = 0,
                        Taille = 10,
                        User = currentUser
                    };
                    ctx.Files.Add(entity);
                    ctx.SaveChanges();

                    fileManager.Create(fileName, "Testing");

            }

            return Content("file Added");
        }
Exemplo n.º 2
0
        public async Task<JsonResult> CreateFile([DataSourceRequest] DataSourceRequest request, File file)
        {
            var currentUser = manager.FindById
                (User.Identity.GetUserId());
            var fileManager = new FileManager(manager.FindById(User.Identity.GetUserId()).Id);
            if (ModelState.IsValid)
            {

                var entity = new File
                {
                    Nom = file.Nom,
                    DateCreation = DateTime.Now,
                    NombreObjets = 145,
                    Taille = 10,
                    User = currentUser
                };
                ApplicationDbContext.Files.Add(entity);
                ApplicationDbContext.SaveChanges();
                file.Id = entity.Id;

                fileManager.Create(file.Nom,"Testing");

            }

            return Json(new[] {file}.ToDataSourceResult(request, ModelState));
        }
Exemplo n.º 3
0
 //
 // GET: /Editor/
 public ActionResult Advanced(string filename,string userId)
 {
     var fileManager = new FileManager(userId);
     string fileData= fileManager.ReadDataFromFile(filename);
     ViewBag.fileData = fileData;
     ViewBag.fileName = filename;
     ViewBag.userId= userId;
     return View();
 }
Exemplo n.º 4
0
        public ActionResult DeleteFileUsingName(string fileName)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(ctx));
                var currentUser = manager.FindById(User.Identity.GetUserId());
                var fileManager = new FileManager(manager.FindById(User.Identity.GetUserId()).Id);

                var query = (from table in ctx.Files
                             where table.Nom == fileName
                             select table).FirstOrDefault();

                ctx.Files.Attach(query);
                ctx.Files.Remove(query);
                ctx.SaveChanges();
                fileManager.Remove(fileName);

            }
            return Content("Fichier supprimé");
        }
Exemplo n.º 5
0
 public virtual ActionResult Download(string fileName, string userId)
 {
     var fileManager = new FileManager(userId);
     var fileData = fileManager.ReadDataFromFile(fileName);
     var contentType = "text/xml";
     var bytes = Encoding.UTF8.GetBytes(fileData);
     var result = new FileContentResult(bytes, contentType);
     result.FileDownloadName = fileName+".idf";
     return result;
 }
Exemplo n.º 6
0
        public ContentResult UpdateFileUsingName(string fileName,string oldName)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(ctx));
                var currentUser = manager.FindById(User.Identity.GetUserId());
                var fileManager = new FileManager(manager.FindById(User.Identity.GetUserId()).Id);

                var query = (from table in ctx.Files
                    where table.Nom == oldName
                    select table).FirstOrDefault();

                if (ModelState.IsValid)
                {
                    if (query != null)
                    {
                        var entity = new File
                        {
                            Id = query.Id,
                            Nom = fileName,
                            DateCreation = query.DateCreation,
                            DateModification = DateTime.Now,
                            NombreObjets = 0,
                            Taille = 10,
                            User = currentUser
                        };
                        var currentFile = ctx.Files.Find(entity.Id);
                        ctx.Entry(currentFile).CurrentValues.SetValues(entity);
                        //ctx.Files.Attach(entity);
                        //ctx.Entry(entity).State = EntityState.Modified;
                    }
                    ctx.SaveChanges();
                    fileManager.RenameFile(oldName, fileName);
                }
            }
            return Content("file Modified");
        }
Exemplo n.º 7
0
 public string SaveFileNoRedirect(string fileData, string fileName, string userId)
 {
     var fileManager = new FileManager(userId);
     fileManager.writeDataToFile(fileName, fileData);
     var source = HostingEnvironment.MapPath(@"~/App_Data/Uploads/" + userId + "/" + fileName + ".idf");
     var destination = HostingEnvironment.MapPath(@"~/localdata/tmp/" + userId + "/" + fileName + ".idf");
     var destinationFolder = HostingEnvironment.MapPath(@"~/localdata/tmp/"); ;
     if (destinationFolder != null && !Directory.Exists(destinationFolder))
     {
         Directory.CreateDirectory(Path.Combine(destinationFolder,userId));
     }
     if (source != null) if (destination != null) System.IO.File.Copy(source, destination, true);
     return "File Saved";
 }
Exemplo n.º 8
0
 public ActionResult SaveFile(string fileData,string fileName,string userId)
 {
     var fileManager = new FileManager(userId);
     fileManager.writeDataToFile(fileName,fileData);
     return RedirectToAction("Index", "Home");
 }