Global.asax.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. userService.UpdateRole(r2);
  215. userService.UpdateRole(r3);
  216. userService.UpdateRole(r4);
  217. // Create appendix base data
  218. var categories = new[]
  219. {
  220. new Category { Description = "RPM" },
  221. new Category { Description = "RM" },
  222. new Category { Description = "Stopftechnik" },
  223. new Category { Description = "Umbauzug" },
  224. new Category { Description = "Logistik" },
  225. new Category { Description = "Oberbau" },
  226. new Category { Description = "Erdbau" },
  227. new Category { Description = "Kabeltiefbau" },
  228. new Category { Description = "Entwässerung" },
  229. new Category { Description = "Sonstiges" }
  230. };
  231. foreach (var category in categories)
  232. appendixService.InsertCategory(category);
  233. var states = new[]
  234. {
  235. new State { Description = "Offen", IsDefault = true, HexColor = "#FFFFFF" },
  236. new State { Description = "Erinnerung Verhandlung", IsDefault = false, HexColor = "#D90800" },
  237. new State { Description = "Verhandelt", IsDefault = false, HexColor = "#CECECE" },
  238. new State { Description = "Erledigt / Entfällt", IsDefault = false, HexColor = "#00A800" }
  239. };
  240. foreach (var state in states)
  241. appendixService.InsertState(state);
  242. var appendices = new[]
  243. {
  244. new Appendix
  245. {
  246. CustomNumber = "3",
  247. Description = "Lückenschluss Weiche 523",
  248. State = states[0],
  249. StateId = states[0].Id,
  250. CategoryValues =
  251. {
  252. new CategoryValue { Category = categories[2], CategoryId = categories[2].Id, Value = 44000 },
  253. new CategoryValue { Category = categories[3], CategoryId = categories[3].Id, Value = 30000 },
  254. },
  255. Value = Convert.ToDecimal(74833.6),
  256. Percentage = (decimal)0.5,
  257. NegotiationValue = 70000,
  258. OfferingDate = new DateTime(2016, 12, 20),
  259. Comment = "hier 3 % NA enthalten = Delta zu iTWO = 77148,04€, Abgabeddatum per Mail, Post später"
  260. },
  261. new Appendix
  262. {
  263. CustomNumber = "6",
  264. Description = "Erschwerniss masch. Gleisbau ZEB 22",
  265. State = states[0],
  266. StateId = states[0].Id,
  267. CategoryValues =
  268. {
  269. new CategoryValue { Category = categories[0], CategoryId = categories[0].Id, Value = 43000 }
  270. },
  271. Value = Convert.ToDecimal(43514.35),
  272. Percentage = (decimal)0.5,
  273. NegotiationValue = 40000,
  274. OfferingDate = new DateTime(2016, 12, 20),
  275. 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"
  276. },
  277. new Appendix
  278. {
  279. CustomNumber = "1",
  280. Description = "Umsetzen von Haufwerken",
  281. State = states[0],
  282. StateId = states[0].Id,
  283. CategoryValues =
  284. {
  285. new CategoryValue { Category = categories[9], CategoryId = categories[9].Id, Value = 2500 }
  286. },
  287. Value = Convert.ToDecimal(2549.18),
  288. Percentage = (decimal)0.5,
  289. NegotiationValue = 2000,
  290. OfferingDate = new DateTime(2017, 2, 2),
  291. Comment = "Beginn der Frist der Nachtragsprüfung 16.02.17"
  292. },
  293. new Appendix
  294. {
  295. CustomNumber = "2",
  296. Description = "Nichtbereitstellung der Ladevorrichtung",
  297. State = states[0],
  298. StateId = states[0].Id,
  299. CategoryValues =
  300. {
  301. new CategoryValue { Category = categories[4], CategoryId = categories[4].Id }
  302. },
  303. Value = Convert.ToDecimal(23738.06),
  304. Percentage = (decimal)0.5,
  305. NegotiationValue = 20000,
  306. OfferingDate = new DateTime(2017, 2, 3),
  307. Comment = "Aufmaße noch nicht erstellt"
  308. }
  309. };
  310. foreach (var appendix in appendices)
  311. appendixService.InsertAppendix(appendix);
  312. // Create site base data
  313. var sites = new[]
  314. {
  315. new Site
  316. {
  317. CustomNumber = "2101000",
  318. Description = "POS Nord Kaiserslautern Los 19-21",
  319. Appendices =
  320. {
  321. appendices[0],
  322. appendices[1]
  323. },
  324. Finished = false,
  325. Start = new DateTime(2016, 1, 1),
  326. Users =
  327. {
  328. u4,
  329. u5,
  330. u6
  331. }
  332. },
  333. new Site
  334. {
  335. CustomNumber = "211200",
  336. Description = "GE Geisenheim-Rüdesheim",
  337. Appendices =
  338. {
  339. appendices[2],
  340. appendices[3]
  341. },
  342. Finished = false,
  343. Start = new DateTime(2016, 1, 1),
  344. Users =
  345. {
  346. u7,
  347. u8,
  348. u9
  349. }
  350. }
  351. };
  352. foreach (var site in sites)
  353. siteService.InsertSite(site);
  354. // Create deviation base data
  355. var kinds = new[]
  356. {
  357. new Kind { Shortance = "MK", Description = "Mehrkosten", IsDefault = true },
  358. new Kind { Shortance = "BH", Description = "Behinderung", IsDefault = false },
  359. new Kind { Shortance = "BD", Description = "Bedenken", IsDefault = false }
  360. };
  361. foreach (var kind in kinds)
  362. deviationService.InsertKind(kind);
  363. var disturbances = new[]
  364. {
  365. new Disturbance { Description = "RPM" },
  366. new Disturbance { Description = "RM" },
  367. new Disturbance { Description = "Stopftechnik" },
  368. new Disturbance { Description = "Umbauzug" },
  369. new Disturbance { Description = "Logistik" },
  370. new Disturbance { Description = "Oberbau" },
  371. new Disturbance { Description = "Erdbau" },
  372. new Disturbance { Description = "Kabeltiefbau" },
  373. new Disturbance { Description = "Entwässerung" },
  374. new Disturbance { Description = "Sonstiges" }
  375. };
  376. foreach (var disturbance in disturbances)
  377. deviationService.InsertDisturbance(disturbance);
  378. var statuses = new[]
  379. {
  380. new Status { Description = "Standard", IsDefault = true },
  381. new Status { Description = "Entfällt", IsDefault = false },
  382. new Status { Description = "Strittig", IsDefault = false },
  383. new Status { Description = "Abr. über HLV", IsDefault = false }
  384. };
  385. foreach (var status in statuses)
  386. deviationService.InsertStatus(status);
  387. var deviations = new[]
  388. {
  389. new Deviation
  390. {
  391. CustomNumber = "1",
  392. Description = "Mehrleistung Stopfen",
  393. Kind = kinds[0],
  394. KindId = kinds[0].Id,
  395. DisturbanceValues =
  396. {
  397. new DisturbanceValue { Disturbance = disturbances[2], DisturbanceId = disturbances[2].Id, Value = 40000 }
  398. },
  399. Status = statuses[0],
  400. StatusId = statuses[0].Id,
  401. Value = 40000,
  402. Percentage = 1,
  403. Appendix = appendices[0],
  404. AppendixId = appendices[0].Id,
  405. AppendixDate = appendices[0].OfferingDate
  406. },
  407. new Deviation
  408. {
  409. CustomNumber = "2",
  410. Description = "Bodenausbau konventionell",
  411. Kind = kinds[0],
  412. KindId = kinds[0].Id,
  413. DisturbanceValues =
  414. {
  415. new DisturbanceValue { Disturbance = disturbances[6], DisturbanceId = disturbances[6].Id, Value = 30000 }
  416. },
  417. Status = statuses[1],
  418. StatusId = statuses[1].Id,
  419. Value = 30000,
  420. Percentage = 0,
  421. Appendix = appendices[0],
  422. AppendixId = appendices[0].Id,
  423. AppendixDate = appendices[0].OfferingDate
  424. },
  425. new Deviation
  426. {
  427. CustomNumber = "3",
  428. Description = "Einbau PSS im Weichenbereich",
  429. Kind = kinds[0],
  430. KindId = kinds[0].Id,
  431. DisturbanceValues =
  432. {
  433. new DisturbanceValue { Disturbance = disturbances[6], DisturbanceId = disturbances[6].Id, Value = 2000 }
  434. },
  435. Status = statuses[0],
  436. StatusId = statuses[0].Id,
  437. Value = 2000,
  438. Percentage = 1,
  439. Appendix = appendices[1],
  440. AppendixId = appendices[1].Id,
  441. AppendixDate = appendices[1].OfferingDate
  442. },
  443. new Deviation
  444. {
  445. CustomNumber = "4",
  446. Description = "Hindernisse bei der PLV mit RPM",
  447. Kind = kinds[1],
  448. KindId = kinds[1].Id,
  449. DisturbanceValues =
  450. {
  451. new DisturbanceValue { Disturbance = disturbances[0], DisturbanceId = disturbances[0].Id, Value = 40000 }
  452. },
  453. Status = statuses[2],
  454. StatusId = statuses[2].Id,
  455. Value = 40000,
  456. Percentage = (decimal)0.3,
  457. Site = sites[0],
  458. SiteId = sites[0].Id
  459. },
  460. new Deviation
  461. {
  462. CustomNumber = "1",
  463. Description = "Umsetzen von Haufwerken",
  464. Kind = kinds[0],
  465. KindId = kinds[0].Id,
  466. DisturbanceValues =
  467. {
  468. new DisturbanceValue { Disturbance = disturbances[6], DisturbanceId = disturbances[6].Id, Value = 2500 }
  469. },
  470. Status = statuses[0],
  471. StatusId = statuses[0].Id,
  472. Value = 2500,
  473. Percentage = 1,
  474. Appendix = appendices[2],
  475. AppendixId = appendices[2].Id,
  476. AppendixDate = appendices[2].OfferingDate
  477. },
  478. new Deviation
  479. {
  480. CustomNumber = "2",
  481. Description = "Nichtbereitsstellung der Ladevorrichtung Nr. 1",
  482. Kind = kinds[0],
  483. KindId = kinds[0].Id,
  484. DisturbanceValues =
  485. {
  486. new DisturbanceValue { Disturbance = disturbances[5], DisturbanceId = disturbances[5].Id, Value = 10000 }
  487. },
  488. Status = statuses[0],
  489. StatusId = statuses[0].Id,
  490. Value = 10000,
  491. Percentage = 1,
  492. Appendix = appendices[3],
  493. AppendixId = appendices[3].Id,
  494. AppendixDate = appendices[3].OfferingDate
  495. },
  496. new Deviation
  497. {
  498. CustomNumber = "5",
  499. Description = "Nichtbereitsstellung der Ladevorrichtung Nr. 2",
  500. Kind = kinds[0],
  501. KindId = kinds[0].Id,
  502. DisturbanceValues =
  503. {
  504. new DisturbanceValue { Disturbance = disturbances[5], DisturbanceId = disturbances[5].Id, Value = 10000 }
  505. },
  506. Status = statuses[3],
  507. StatusId = statuses[3].Id,
  508. Value = 10000,
  509. Percentage = 1,
  510. Appendix = appendices[3],
  511. AppendixId = appendices[3].Id,
  512. AppendixDate = appendices[3].OfferingDate
  513. },
  514. new Deviation
  515. {
  516. CustomNumber = "6",
  517. Description = "Verspannung Los 2",
  518. Kind = kinds[0],
  519. KindId = kinds[0].Id,
  520. DisturbanceValues =
  521. {
  522. new DisturbanceValue { Disturbance = disturbances[5], DisturbanceId = disturbances[5].Id, Value = 6000 }
  523. },
  524. Status = statuses[2],
  525. StatusId = statuses[2].Id,
  526. Value = 6000,
  527. Percentage = (decimal)0.5,
  528. Site = sites[1],
  529. SiteId = sites[1].Id
  530. }
  531. };
  532. foreach (var deviation in deviations)
  533. deviationService.InsertDeviation(deviation);
  534. }
  535. finally
  536. {
  537. // Create DbContecSpecification object
  538. var db1 = new DbContextSpec
  539. {
  540. Name = "IsTestDataGenerated",
  541. Value = "True"
  542. };
  543. dbContext.Get<DbContextSpec>().Add(db1);
  544. dbContext.SaveChanges();
  545. }
  546. }
  547. #endregion
  548. }
  549. }