-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathHomeController.cs
55 lines (49 loc) · 1.88 KB
/
HomeController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DevExpress.DataAccess.Sql;
using Mvc_DbStorage_Sample.Services.DAL;
using System.Web.Mvc;
using DevExpress.Xpo;
namespace Mvc_DbStorage_Sample.Controllers {
public class HomeController : Controller {
[HttpGet]
public ActionResult Index() {
using (var session = SessionFactory.Create()) {
var reports = session.Query<ReportEntity>()
.Select(x => new ReportModel {
Url = x.Url
})
.ToArray();
var firstReport = reports.FirstOrDefault();
var model = new IndexModel {
SelectedReportUrl = firstReport != null ? firstReport.Url : String.Empty,
Reports = reports
};
return View("Index", model);
}
}
[HttpPost]
public ActionResult Delete(string url) {
using (var session = SessionFactory.Create()) {
var report = session.GetObjectByKey<ReportEntity>(url);
session.Delete(report);
session.CommitChanges();
}
return Index();
}
[HttpPost]
public ActionResult Design(string url) {
return View("Designer", new DesignModel { Url = url, DataSource = CreateSqlDataSource() });
}
SqlDataSource CreateSqlDataSource() {
SqlDataSource ds = new SqlDataSource("NWindConnectionString");
ds.Name = "NWind";
SelectQuery categoriesQuery = SelectQueryFluentBuilder.AddTable("Categories").SelectAllColumns().Build("Categories");
ds.Queries.Add(categoriesQuery);
ds.RebuildResultSchema();
return ds;
}
}
}