Global.asax.cs 26 KB

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