Global.asax.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. namespace GreenTree.Nachtragsmanagement.Web
  25. {
  26. // Note: For instructions on enabling IIS6 or IIS7 classic mode,
  27. // visit http://go.microsoft.com/?LinkId=9394801
  28. public class MvcApplication : System.Web.HttpApplication
  29. {
  30. protected void Application_Start()
  31. {
  32. AreaRegistration.RegisterAllAreas();
  33. GlobalConfiguration.Configure(WebApiConfig.Register);
  34. FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
  35. RouteConfig.RegisterRoutes(RouteTable.Routes);
  36. BundleConfig.RegisterBundles(BundleTable.Bundles);
  37. ModelBinders.Binders.DefaultBinder = new DevExpress.Web.Mvc.DevExpressEditorsBinder();
  38. ApplicationContext.InitApplication();
  39. ApplicationContext.InitPluginRoutes(RouteTable.Routes);
  40. FunctionConfig.RegisterFunctions();
  41. FluentValidationModelValidatorProvider.Configure(provider =>
  42. {
  43. provider.ValidatorFactory = new AppendixValidatorFactory();
  44. });
  45. DevExpress.Web.ASPxWebControl.CallbackError += Application_Error;
  46. GenerateTestData();
  47. }
  48. protected void Application_Error(object sender, EventArgs e)
  49. {
  50. Exception exception = System.Web.HttpContext.Current.Server.GetLastError();
  51. //TODO: Handle Exception
  52. }
  53. #region Test
  54. private void GenerateTestData()
  55. {
  56. // Get services
  57. var dbContext = Singleton<IContainer>.Instance.Resolve<IDbContext>();
  58. var userService = Singleton<IContainer>.Instance.Resolve<IUserService>();
  59. var deviationService = Singleton<IContainer>.Instance.Resolve<IDeviationService>();
  60. // Check if test data is already created
  61. var isTestDataGeneratedEntity = dbContext.Get<DbContextSpec>().FirstOrDefault(d => d.Name == "IsTestDataGenerated");
  62. if (isTestDataGeneratedEntity != null && Convert.ToBoolean(isTestDataGeneratedEntity.Value))
  63. return;
  64. // Create base data
  65. var kinds = new []
  66. {
  67. new Kind { Shortance = "MK", Description = "Mehrkosten" },
  68. new Kind { Shortance = "BH", Description = "Behinderung" },
  69. new Kind { Shortance = "BD", Description = "Bedenken" }
  70. };
  71. foreach (var kind in kinds)
  72. deviationService.InsertKind(kind);
  73. var disturbances = new[]
  74. {
  75. new Disturbance { Description = "RPM" },
  76. new Disturbance { Description = "RM" },
  77. new Disturbance { Description = "Stopftechnik" },
  78. new Disturbance { Description = "Umbauzug" },
  79. new Disturbance { Description = "Logistik" },
  80. new Disturbance { Description = "Oberbau" },
  81. new Disturbance { Description = "Erdbau" },
  82. new Disturbance { Description = "Kabeltiefbau" },
  83. new Disturbance { Description = "Entwässerung" },
  84. new Disturbance { Description = "Sonstiges" }
  85. };
  86. foreach (var disturbance in disturbances)
  87. deviationService.InsertDisturbance(disturbance);
  88. var statuses = new []
  89. {
  90. new Status { Description = "Standard" },
  91. new Status { Description = "Entfällt" },
  92. new Status { Description = "Strittig" },
  93. new Status { Description = "Abr. über HLV" }
  94. };
  95. foreach (var status in statuses)
  96. deviationService.InsertStatus(status);
  97. // Create roles
  98. var r1 = new Role
  99. {
  100. Description = "Administrator",
  101. Level = 100
  102. };
  103. userService.InsertRole(r1);
  104. var r2 = new Role
  105. {
  106. Description = "Kaufmann",
  107. Level = 10
  108. };
  109. userService.InsertRole(r2);
  110. var r3 = new Role
  111. {
  112. Description = "Nachtragsmanager",
  113. Level = 10
  114. };
  115. userService.InsertRole(r3);
  116. // Create users
  117. var u1 = new User
  118. {
  119. Forename = "Arne",
  120. Lastname = "Diekmann",
  121. CustomNumber = "a.diekmann",
  122. MailAddress = "a.diekmann@greentreestudios.de",
  123. Password = StaticHelper.GetMD5Hash("14595809")
  124. };
  125. userService.InsertUser(u1);
  126. var u2 = new User
  127. {
  128. Forename = "Rocco",
  129. Lastname = "Lavella",
  130. CustomNumber = "r.lavella",
  131. MailAddress = "lavella@schweerbau.de",
  132. Password = StaticHelper.GetMD5Hash("lavella")
  133. };
  134. userService.InsertUser(u2);
  135. var u3 = new User
  136. {
  137. Forename = "Kletus",
  138. Lastname = "Lingemann",
  139. CustomNumber = "k.lingemann",
  140. MailAddress = "k.lingemann@schweerbau.de",
  141. Password = StaticHelper.GetMD5Hash("lingemann")
  142. };
  143. userService.InsertUser(u3);
  144. // Add users to roles
  145. u1.Roles.Add(r1);
  146. u2.Roles.Add(r1);
  147. u3.Roles.Add(r3);
  148. // Get all functions and add them to the admin role
  149. var allFunctions = userService.GetAllFunctions();
  150. r1.SetFunctions(allFunctions);
  151. userService.UpdateRole(r1);
  152. // Get all appendix manager function and add them to the apendix manager / merchant role
  153. var deviationFunctions = allFunctions
  154. .Where(f => f.Name.StartsWith("Deviation"));
  155. foreach (var function in deviationFunctions)
  156. {
  157. r2.Functions.Add(function);
  158. r3.Functions.Add(function);
  159. }
  160. var appendixFunctions = allFunctions
  161. .Where(f => f.Name.StartsWith("Appendix"));
  162. foreach (var function in appendixFunctions)
  163. {
  164. r2.Functions.Add(function);
  165. r3.Functions.Add(function);
  166. }
  167. userService.UpdateRole(r2);
  168. userService.UpdateRole(r3);
  169. // Create DbContecSpecification object
  170. var db1 = new DbContextSpec
  171. {
  172. Name = "IsTestDataGenerated",
  173. Value = "True"
  174. };
  175. dbContext.Get<DbContextSpec>().Add(db1);
  176. }
  177. #endregion
  178. }
  179. }