// GET: Home/Details/5 public ActionResult Details(int id) { SamplesEntities db = new SamplesEntities(); Books book = db.Books.Single(x => x.book_id == id); return(View(book)); }
// GET: Home public ActionResult Index() { SamplesEntities db = new SamplesEntities(); IEnumerable <Books> books = db.Books.ToList(); return(View(books)); }
public MainWindowViewModel() { this.context = new SamplesEntities(); //"Data Source=IronPythonSample.sdf"); this.ShowSpeakersCommand = new GenericCommand( x => this.WindowContent == WindowContent.Sessions, x => this.WindowContent = WindowContent.Speakers, this); this.ShowSessionsCommand = new GenericCommand( x => this.WindowContent == WindowContent.Speakers, x => this.WindowContent = WindowContent.Sessions, this); this.RunScriptCommand = new GenericCommand( x => true, x => { OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = ".py"; dlg.Filter = "Python script (.py)|*.py"; var result = dlg.ShowDialog(); if (result.HasValue && result.Value) { Task.Factory.StartNew(() => this.RunScript(dlg.FileName)); } }); this.EraseOutputCommand = new GenericCommand( x => true, x => { lock (this.scriptOutput) { this.scriptOutput = new StringBuilder(); } this.OnPropertyChanged("ScriptOutput"); }); this.ApproveSessionCommand = new GenericCommand( x => this.SelectedSession != null, x => { var engine = Python.CreateEngine(); var scope = engine.CreateScope(); scope.SetVariable("viewModel", this); engine.CreateScriptSourceFromString(@" viewModel.SelectedSession.Approved = True viewModel.SaveChanges() ").Execute(scope); }, this); this.SpeakerExportCommand = new GenericCommand( x => true, x => { var engine = Python.CreateEngine(); var scope = engine.CreateScope(); var scriptSource = @" import clr clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c') clr.AddReference(""System.Core"") from Microsoft.Office.Interop import * from Microsoft.Office.Interop.Excel import * from System import * def export(speakers): ex = Excel.ApplicationClass() ex.Visible = True ex.DisplayAlerts = False workbook = ex.Workbooks.Add() ws = workbook.Worksheets[1] rowIndex = 1 for speaker in speakers: ws.Cells[rowIndex, 1].Value2 = speaker.FirstName ws.Cells[rowIndex, 2].Value2 = speaker.LastName ws.Cells[rowIndex, 3].Value2 = speaker.FullName ws.Cells[rowIndex, 4].Value2 = speaker.NumberOfApprovedSessions rowIndex = rowIndex + 1"; engine.CreateScriptSourceFromString(scriptSource).Execute(scope); object exportFunc = scope.GetVariable("export"); engine.Operations.Invoke(exportFunc, this.Speakers); }); this.PropertyChanged += (s, e) => { if (e.PropertyName == "WindowContent") { OnWindowContentChanged(); } }; this.WindowContent = WindowContent.Speakers; }