Global.asax.cs 25 KB

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