Exemplo n.º 1
0
 public void DeleteFolder(Folder folder)
 {
     using (var context = new FileManagerContext())
     {
         context.Folders.Attach(folder);
         context.Entry(folder).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Exemplo n.º 2
0
 public void AddFile(File file)
 {
     using (var context = new FileManagerContext())
     {
         file.CreationDate = DateTime.Now;
         context.Files.Attach(file);
         context.Entry(file).State = EntityState.Added;
         context.SaveChanges();
     }
 }
Exemplo n.º 3
0
 public void DeleteFile(int fileId)
 {
     using (var context = new FileManagerContext())
     {
         var file = (from f in context.Files
                     where f.FileId == fileId
                     select f).FirstOrDefault();
         context.Files.Attach(file);
         context.Entry(file).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Exemplo n.º 4
0
        public void UpdateFileComments(int fileId, string comment)
        {
            File file;

            using (var context = new FileManagerContext())
            {
                file = (from f in context.Files
                        where f.FileId == fileId
                        select f).FirstOrDefault();

                var newComment = new FileComment();
                newComment.CommentText = comment;
                newComment.FileId      = file.FileId;
                context.FileComments.Add(newComment);
                context.SaveChanges();
                context.Files.Attach(file);
                context.Entry(file).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public void RenameFile(File file)
        {
            File oldFile;

            using (var context = new FileManagerContext())
            {
                oldFile = (from f in context.Files
                           where f.FileId == file.FileId
                           select f).FirstOrDefault();
            }
            var nameChange = new FileNameChange();

            if (oldFile.FileName != file.FileName)
            {
                nameChange.FileChangeDate = DateTime.Now;
                nameChange.FileId         = file.FileId;
                nameChange.OldName        = oldFile.FileName;
                nameChange.NewName        = file.FileName;

                if (file.FileNameChanges == null)
                {
                    file.FileNameChanges = new List <FileNameChange>();
                }

                file.FileNameChanges.Add(nameChange);
            }
            file.FileContent = oldFile.FileContent;

            using (var context = new FileManagerContext())
            {
                context.FileNameChanges.Add(nameChange);
                context.SaveChanges();
                context.Files.Attach(file);
                context.Entry(file).State = EntityState.Modified;
                context.SaveChanges();
            }
        }