public FileNameChangeModel(FileNameChange domain) { this.Id = domain.Id; this.OldName = domain.OldName; this.NewName = domain.NewName; this.FileId = domain.FileId; this.Date = domain.FileChangeDate.ToShortDateString(); }
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(); } }