public StorageItem TrashItem(int id) { StorageItem itemToTrash = GetById(id); itemToTrash.IsTrash = true; _context.StorageItems.Update(itemToTrash); _context.SaveChanges(); return(itemToTrash); }
public void DeleteFolder(Folder folder) { using (var context = new FileManagerContext()) { context.Folders.Attach(folder); context.Entry(folder).State = EntityState.Deleted; context.SaveChanges(); } }
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(); } }
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(); } }
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(); } }
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(); } }