Example #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");
        }
Example #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));
        }
Example #3
0
        public async Task<JsonResult> UpdateFile([DataSourceRequest] DataSourceRequest request, File file)
        {
            var currentUser = manager.FindById
                (User.Identity.GetUserId());
            if (ModelState.IsValid)
            {

                var entity = new File
                {
                    Id = file.Id,
                    Nom = file.Nom,
                    DateCreation = file.DateCreation,
                    DateModification = DateTime.Now,
                    NombreObjets = 145,
                    Taille = 10,
                    User = currentUser
                };

                ApplicationDbContext.Files.Attach(entity);
                ApplicationDbContext.Entry(entity).State = EntityState.Modified;
                ApplicationDbContext.SaveChanges();
            }
            return Json(new[] {file}.ToDataSourceResult(request, ModelState));
        }
Example #4
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");
        }