Global.asax.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Http;
  6. using System.Web.Mvc;
  7. using System.Web.Routing;
  8. using GreenTree.Nachtragsmanagement.Web.Framework;
  9. using GreenTree.Nachtragsmanagement.Core.Domain;
  10. using System.Reflection;
  11. using GreenTree.Nachtragsmanagement.Core;
  12. using Autofac;
  13. using GreenTree.Nachtragsmanagement.Web.Framework.Mvc.Routes;
  14. using GreenTree.Nachtragsmanagement.Web.App_Start;
  15. using System.Web.Optimization;
  16. using FluentValidation.Mvc;
  17. using GreenTree.Nachtragsmanagement.Web.Validation;
  18. using GreenTree.Nachtragsmanagement.Services.User;
  19. using GreenTree.Nachtragsmanagement.Data;
  20. using GreenTree.Nachtragsmanagement.Core.Domain.Misc;
  21. using GreenTree.Nachtragsmanagement.Core.Domain.User;
  22. using GreenTree.Nachtragsmanagement.Core.Domain.Deviation;
  23. using GreenTree.Nachtragsmanagement.Services.Deviation;
  24. using GreenTree.Nachtragsmanagement.Core.Domain.Site;
  25. using GreenTree.Nachtragsmanagement.Core.Domain.Appendix;
  26. using GreenTree.Nachtragsmanagement.Services.Appendix;
  27. using GreenTree.Nachtragsmanagement.Services.Site;
  28. namespace GreenTree.Nachtragsmanagement.Web
  29. {
  30. // Note: For instructions on enabling IIS6 or IIS7 classic mode,
  31. // visit http://go.microsoft.com/?LinkId=9394801
  32. public class MvcApplication : System.Web.HttpApplication
  33. {
  34. protected void Application_Start()
  35. {
  36. AreaRegistration.RegisterAllAreas();
  37. GlobalConfiguration.Configure(WebApiConfig.Register);
  38. FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
  39. RouteConfig.RegisterRoutes(RouteTable.Routes);
  40. BundleConfig.RegisterBundles(BundleTable.Bundles);
  41. ModelBinders.Binders.DefaultBinder = new DevExpress.Web.Mvc.DevExpressEditorsBinder();
  42. ApplicationContext.InitApplication();
  43. ApplicationContext.InitPluginRoutes(RouteTable.Routes);
  44. FunctionConfig.RegisterFunctions();
  45. FluentValidationModelValidatorProvider.Configure(provider =>
  46. {
  47. provider.ValidatorFactory = new AppendixValidatorFactory();
  48. });
  49. DevExpress.Web.ASPxWebControl.CallbackError += Application_Error;
  50. GenerateTestData();
  51. }
  52. protected void Application_Error(object sender, EventArgs e)
  53. {
  54. Exception exception = System.Web.HttpContext.Current.Server.GetLastError();
  55. //TODO: Handle Exception
  56. }
  57. #region Test
  58. private void GenerateTestData()
  59. {
  60. // Get services
  61. var userService = Singleton<IContainer>.Instance.Resolve<IUserService>();
  62. var deviationService = Singleton<IContainer>.Instance.Resolve<IDeviationService>();
  63. var appendixService = Singleton<IContainer>.Instance.Resolve<IAppendixService>();
  64. var siteService = Singleton<IContainer>.Instance.Resolve<ISiteService>();
  65. var dbContext = Singleton<IContainer>.Instance.Resolve<IDbContext>();
  66. try
  67. {
  68. // Check if test data is already created
  69. var isTestDataGeneratedEntity = dbContext.Get<DbContextSpec>().FirstOrDefault(d => d.Name == "IsTestDataGenerated");
  70. if (isTestDataGeneratedEntity != null && Convert.ToBoolean(isTestDataGeneratedEntity.Value))
  71. return;
  72. // Create roles
  73. var r1 = new Role
  74. {
  75. Description = "Administrator",
  76. Level = 100
  77. };
  78. userService.InsertRole(r1);
  79. var r2 = new Role
  80. {
  81. Description = "Kaufmann",
  82. Level = 10
  83. };
  84. userService.InsertRole(r2);
  85. var r3 = new Role
  86. {
  87. Description = "Nachtragsmanager",
  88. Level = 10
  89. };
  90. userService.InsertRole(r3);
  91. var r4 = new Role
  92. {
  93. Description = "Bauleiter",
  94. Level = 10
  95. };
  96. userService.InsertRole(r4);
  97. // Create users
  98. var u1 = new User
  99. {
  100. Forename = "Arne",
  101. Lastname = "Diekmann",
  102. CustomNumber = "a.diekmann",
  103. MailAddress = "a.diekmann@greentreestudios.de",
  104. Password = StaticHelper.GetMD5Hash("14595809")
  105. };
  106. userService.InsertUser(u1);
  107. var u2 = new User
  108. {
  109. Forename = "Rocco",
  110. Lastname = "Lavella",
  111. CustomNumber = "r.lavella",
  112. MailAddress = "lavella@schweerbau.de",
  113. Password = StaticHelper.GetMD5Hash("lavella")
  114. };
  115. userService.InsertUser(u2);
  116. var u3 = new User
  117. {
  118. Forename = "Felix",
  119. Lastname = "Bramstedt",
  120. CustomNumber = "f.bramstedt",
  121. MailAddress = "bramstedt@schweerbau.de",
  122. Password = StaticHelper.GetMD5Hash("bramstedt")
  123. };
  124. userService.InsertUser(u3);
  125. var u4 = new User
  126. {
  127. Forename = "Kletus",
  128. Lastname = "Lingemann",
  129. CustomNumber = "k.lingemann",
  130. MailAddress = "lingemann@schweerbau.de",
  131. Password = StaticHelper.GetMD5Hash("lingemann")
  132. };
  133. userService.InsertUser(u4);
  134. var u5 = new User
  135. {
  136. Forename = "Max",
  137. Lastname = "Moede",
  138. CustomNumber = "m.moede",
  139. MailAddress = "moede@schweerbau.de",
  140. Password = StaticHelper.GetMD5Hash("moede")
  141. };
  142. userService.InsertUser(u5);
  143. var u6 = new User
  144. {
  145. Forename = "Max",
  146. Lastname = "Dammeier",
  147. CustomNumber = "m.dammeier",
  148. MailAddress = "dammeier@schweerbau.de",
  149. Password = StaticHelper.GetMD5Hash("dammeier")
  150. };
  151. userService.InsertUser(u6);
  152. var u7 = new User
  153. {
  154. Forename = "Max",
  155. Lastname = "Poppe",
  156. CustomNumber = "m.poppe",
  157. MailAddress = "poppe@schweerbau.de",
  158. Password = StaticHelper.GetMD5Hash("poppe")
  159. };
  160. userService.InsertUser(u7);
  161. var u8 = new User
  162. {
  163. Forename = "Max",
  164. Lastname = "Lehmann",
  165. CustomNumber = "m.lehmann",
  166. MailAddress = "lehmann@schweerbau.de",
  167. Password = StaticHelper.GetMD5Hash("poppe")
  168. };
  169. userService.InsertUser(u8);
  170. var u9 = new User
  171. {
  172. Forename = "Max",
  173. Lastname = "Wernecke",
  174. CustomNumber = "m.wernecke",
  175. MailAddress = "wernecke@schweerbau.de",
  176. Password = StaticHelper.GetMD5Hash("wernecke")
  177. };
  178. userService.InsertUser(u9);
  179. // Add users to roles
  180. u1.Roles.Add(r1);
  181. u2.Roles.Add(r1);
  182. u3.Roles.Add(r1);
  183. u4.Roles.Add(r3);
  184. u4.Roles.Add(r3);
  185. u5.Roles.Add(r4);
  186. u7.Roles.Add(r4);
  187. u6.Roles.Add(r2);
  188. u9.Roles.Add(r2);
  189. // Get all functions and add them to the admin role
  190. var allFunctions = userService.GetAllFunctions();
  191. r1.SetFunctions(allFunctions);
  192. userService.UpdateRole(r1);
  193. // Get all appendix manager function and add them to the apendix manager / merchant role
  194. var deviationFunctions = allFunctions
  195. .Where(f => f.Name.StartsWith("Deviation"));
  196. foreach (var function in deviationFunctions)
  197. {
  198. r2.Functions.Add(function);
  199. r3.Functions.Add(function);
  200. r4.Functions.Add(function);
  201. }
  202. var appendixFunctions = allFunctions
  203. .Where(f => f.Name.StartsWith("Appendix"));
  204. foreach (var function in appendixFunctions)
  205. {
  206. r2.Functions.Add(function);
  207. r3.Functions.Add(function);
  208. r4.Functions.Add(function);
  209. }
  210. userService.UpdateRole(r2);
  211. userService.UpdateRole(r3);
  212. userService.UpdateRole(r4);
  213. // Create appendix base data
  214. var categories = new[]
  215. {
  216. new Category { Description = "RPM" },
  217. new Category { Description = "RM" },
  218. new Category { Description = "Stopftechnik" },
  219. new Category { Description = "Umbauzug" },
  220. new Category { Description = "Logistik" },
  221. new Category { Description = "Oberbau" },
  222. new Category { Description = "Erdbau" },
  223. new Category { Description = "Kabeltiefbau" },
  224. new Category { Description = "Entwässerung" },
  225. new Category { Description = "Sonstiges" }
  226. };
  227. foreach (var category in categories)
  228. appendixService.InsertCategory(category);
  229. var states = new[]
  230. {
  231. new State { Description = "Offen" },
  232. new State { Description = "Erinnerung Verhandlung" },
  233. new State { Description = "Verhandelt" },
  234. new State { Description = "Erledigt / Entfällt" }
  235. };
  236. foreach (var state in states)
  237. appendixService.InsertState(state);
  238. var appendices = new[]
  239. {
  240. new Appendix
  241. {
  242. CustomNumber = "3",
  243. Description = "Lückenschluss Weiche 523",
  244. State = states[0],
  245. StateId = states[0].Id,
  246. CategoryValues =
  247. {
  248. new CategoryValue { Category = categories[2], CategoryId = categories[2].Id, Value = 44000 },
  249. new CategoryValue { Category = categories[3], CategoryId = categories[3].Id, Value = 30000 },
  250. },
  251. Value = Convert.ToDecimal(74833.6),
  252. NegotiationValue = 70000,
  253. OfferingDate = new DateTime(2016, 12, 20),
  254. Comment = "hier 3 % NA enthalten = Delta zu iTWO = 77148,04€, Abgabeddatum per Mail, Post später"
  255. },
  256. new Appendix
  257. {
  258. CustomNumber = "6",
  259. Description = "Erschwerniss masch. Gleisbau ZEB 22",
  260. State = states[0],
  261. StateId = states[0].Id,
  262. CategoryValues =
  263. {
  264. new CategoryValue { Category = categories[0], CategoryId = categories[0].Id, Value = 43000 }
  265. },
  266. Value = Convert.ToDecimal(43514.35),
  267. NegotiationValue = 40000,
  268. OfferingDate = new DateTime(2016, 12, 20),
  269. Comment = "Teilweise Abrechnung über HLV in Höhe von 5322,12€ (nicht in Summe oben enthalten) hier 3 % NA enthalten = Delta zu iTWO = 44860,15€ Abgabeddatum per Mail, Post später"
  270. },
  271. new Appendix
  272. {
  273. CustomNumber = "1",
  274. Description = "Umsetzen von Haufwerken",
  275. State = states[0],
  276. StateId = states[0].Id,
  277. CategoryValues =
  278. {
  279. new CategoryValue { Category = categories[9], CategoryId = categories[9].Id, Value = 2500 }
  280. },
  281. Value = Convert.ToDecimal(2549.18),
  282. NegotiationValue = 2000,
  283. OfferingDate = new DateTime(2017, 2, 2),
  284. Comment = "Beginn der Frist der Nachtragsprüfung 16.02.17"
  285. },
  286. new Appendix
  287. {
  288. CustomNumber = "2",
  289. Description = "Nichtbereitstellung der Ladevorrichtung",
  290. State = states[0],
  291. StateId = states[0].Id,
  292. CategoryValues =
  293. {
  294. new CategoryValue { Category = categories[4], CategoryId = categories[4].Id }
  295. },
  296. Value = Convert.ToDecimal(23738.06),
  297. NegotiationValue = 20000,
  298. OfferingDate = new DateTime(2017, 2, 3),
  299. Comment = "Aufmaße noch nicht erstellt"
  300. }
  301. };
  302. foreach (var appendix in appendices)
  303. appendixService.InsertAppendix(appendix);
  304. // Create site base data
  305. var sites = new[]
  306. {
  307. new Site
  308. {
  309. CustomNumber = "2101000",
  310. Description = "POS Nord Kaiserslautern Los 19-21",
  311. Appendices =
  312. {
  313. appendices[0],
  314. appendices[1]
  315. },
  316. Finished = false,
  317. Start = new DateTime(2016, 1, 1),
  318. Users =
  319. {
  320. u4,
  321. u5,
  322. u6
  323. }
  324. },
  325. new Site
  326. {
  327. CustomNumber = "211200",
  328. Description = "GE Geisenheim-Rüdesheim",
  329. Appendices =
  330. {
  331. appendices[2],
  332. appendices[3]
  333. },
  334. Finished = false,
  335. Start = new DateTime(2016, 1, 1),
  336. Users =
  337. {
  338. u7,
  339. u8,
  340. u9
  341. }
  342. }
  343. };
  344. foreach (var site in sites)
  345. siteService.InsertSite(site);
  346. // Create deviation base data
  347. var kinds = new[]
  348. {
  349. new Kind { Shortance = "MK", Description = "Mehrkosten" },
  350. new Kind { Shortance = "BH", Description = "Behinderung" },
  351. new Kind { Shortance = "BD", Description = "Bedenken" }
  352. };
  353. foreach (var kind in kinds)
  354. deviationService.InsertKind(kind);
  355. var disturbances = new[]
  356. {
  357. new Disturbance { Description = "RPM" },
  358. new Disturbance { Description = "RM" },
  359. new Disturbance { Description = "Stopftechnik" },
  360. new Disturbance { Description = "Umbauzug" },
  361. new Disturbance { Description = "Logistik" },
  362. new Disturbance { Description = "Oberbau" },
  363. new Disturbance { Description = "Erdbau" },
  364. new Disturbance { Description = "Kabeltiefbau" },
  365. new Disturbance { Description = "Entwässerung" },
  366. new Disturbance { Description = "Sonstiges" }
  367. };
  368. foreach (var disturbance in disturbances)
  369. deviationService.InsertDisturbance(disturbance);
  370. var statuses = new[]
  371. {
  372. new Status { Description = "Standard" },
  373. new Status { Description = "Entfällt" },
  374. new Status { Description = "Strittig" },
  375. new Status { Description = "Abr. über HLV" }
  376. };
  377. foreach (var status in statuses)
  378. deviationService.InsertStatus(status);
  379. var deviations = new[]
  380. {
  381. new Deviation
  382. {
  383. CustomNumber = "1",
  384. Description = "Mehrleistung Stopfen",
  385. Kind = kinds[0],
  386. KindId = kinds[0].Id,
  387. DisturbanceValues =
  388. {
  389. new DisturbanceValue { Disturbance = disturbances[2], DisturbanceId = disturbances[2].Id, Value = 40000 }
  390. },
  391. Status = statuses[0],
  392. StatusId = statuses[0].Id,
  393. Value = 40000,
  394. Percentage = 100,
  395. Appendix = appendices[0],
  396. AppendixId = appendices[0].Id,
  397. AppendixDate = appendices[0].OfferingDate
  398. },
  399. new Deviation
  400. {
  401. CustomNumber = "2",
  402. Description = "Bodenausbau konventionell",
  403. Kind = kinds[0],
  404. KindId = kinds[0].Id,
  405. DisturbanceValues =
  406. {
  407. new DisturbanceValue { Disturbance = disturbances[6], DisturbanceId = disturbances[6].Id, Value = 30000 }
  408. },
  409. Status = statuses[1],
  410. StatusId = statuses[1].Id,
  411. Value = 30000,
  412. Percentage = 0,
  413. Appendix = appendices[0],
  414. AppendixId = appendices[0].Id,
  415. AppendixDate = appendices[0].OfferingDate
  416. },
  417. new Deviation
  418. {
  419. CustomNumber = "3",
  420. Description = "Einbau PSS im Weichenbereich",
  421. Kind = kinds[0],
  422. KindId = kinds[0].Id,
  423. DisturbanceValues =
  424. {
  425. new DisturbanceValue { Disturbance = disturbances[6], DisturbanceId = disturbances[6].Id, Value = 2000 }
  426. },
  427. Status = statuses[0],
  428. StatusId = statuses[0].Id,
  429. Value = 2000,
  430. Percentage = 100,
  431. Appendix = appendices[1],
  432. AppendixId = appendices[1].Id,
  433. AppendixDate = appendices[1].OfferingDate
  434. },
  435. new Deviation
  436. {
  437. CustomNumber = "4",
  438. Description = "Hindernisse bei der PLV mit RPM",
  439. Kind = kinds[1],
  440. KindId = kinds[1].Id,
  441. DisturbanceValues =
  442. {
  443. new DisturbanceValue { Disturbance = disturbances[0], DisturbanceId = disturbances[0].Id, Value = 40000 }
  444. },
  445. Status = statuses[2],
  446. StatusId = statuses[2].Id,
  447. Value = 40000,
  448. Percentage = 30,
  449. Site = sites[0],
  450. SiteId = sites[0].Id
  451. },
  452. new Deviation
  453. {
  454. CustomNumber = "1",
  455. Description = "Umsetzen von Haufwerken",
  456. Kind = kinds[0],
  457. KindId = kinds[0].Id,
  458. DisturbanceValues =
  459. {
  460. new DisturbanceValue { Disturbance = disturbances[6], DisturbanceId = disturbances[6].Id, Value = 2500 }
  461. },
  462. Status = statuses[0],
  463. StatusId = statuses[0].Id,
  464. Value = 2500,
  465. Percentage = 100,
  466. Appendix = appendices[2],
  467. AppendixId = appendices[2].Id,
  468. AppendixDate = appendices[2].OfferingDate
  469. },
  470. new Deviation
  471. {
  472. CustomNumber = "2",
  473. Description = "Nichtbereitsstellung der Ladevorrichtung Nr. 1",
  474. Kind = kinds[0],
  475. KindId = kinds[0].Id,
  476. DisturbanceValues =
  477. {
  478. new DisturbanceValue { Disturbance = disturbances[5], DisturbanceId = disturbances[5].Id, Value = 10000 }
  479. },
  480. Status = statuses[0],
  481. StatusId = statuses[0].Id,
  482. Value = 10000,
  483. Percentage = 100,
  484. Appendix = appendices[3],
  485. AppendixId = appendices[3].Id,
  486. AppendixDate = appendices[3].OfferingDate
  487. },
  488. new Deviation
  489. {
  490. CustomNumber = "5",
  491. Description = "Nichtbereitsstellung der Ladevorrichtung Nr. 2",
  492. Kind = kinds[0],
  493. KindId = kinds[0].Id,
  494. DisturbanceValues =
  495. {
  496. new DisturbanceValue { Disturbance = disturbances[5], DisturbanceId = disturbances[5].Id, Value = 10000 }
  497. },
  498. Status = statuses[3],
  499. StatusId = statuses[3].Id,
  500. Value = 10000,
  501. Percentage = 110,
  502. Appendix = appendices[3],
  503. AppendixId = appendices[3].Id,
  504. AppendixDate = appendices[3].OfferingDate
  505. },
  506. new Deviation
  507. {
  508. CustomNumber = "6",
  509. Description = "Verspannung Los 2",
  510. Kind = kinds[0],
  511. KindId = kinds[0].Id,
  512. DisturbanceValues =
  513. {
  514. new DisturbanceValue { Disturbance = disturbances[5], DisturbanceId = disturbances[5].Id, Value = 6000 }
  515. },
  516. Status = statuses[2],
  517. StatusId = statuses[2].Id,
  518. Value = 6000,
  519. Percentage = 50,
  520. Site = sites[1],
  521. SiteId = sites[1].Id
  522. }
  523. };
  524. foreach (var deviation in deviations)
  525. deviationService.InsertDeviation(deviation);
  526. }
  527. finally
  528. {
  529. // Create DbContecSpecification object
  530. var db1 = new DbContextSpec
  531. {
  532. Name = "IsTestDataGenerated",
  533. Value = "True"
  534. };
  535. dbContext.Get<DbContextSpec>().Add(db1);
  536. dbContext.SaveChanges();
  537. }
  538. }
  539. #endregion
  540. }
  541. }