| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Http;
- using System.Web.Mvc;
- using System.Web.Routing;
- using GreenTree.Nachtragsmanagement.Web.Framework;
- using GreenTree.Nachtragsmanagement.Core.Domain;
- using System.Reflection;
- using GreenTree.Nachtragsmanagement.Core;
- using Autofac;
- using GreenTree.Nachtragsmanagement.Web.Framework.Mvc.Routes;
- using GreenTree.Nachtragsmanagement.Web.App_Start;
- using System.Web.Optimization;
- using FluentValidation.Mvc;
- using GreenTree.Nachtragsmanagement.Web.Validation;
- using GreenTree.Nachtragsmanagement.Services.User;
- using GreenTree.Nachtragsmanagement.Data;
- using GreenTree.Nachtragsmanagement.Core.Domain.Misc;
- using GreenTree.Nachtragsmanagement.Core.Domain.User;
- using GreenTree.Nachtragsmanagement.Core.Domain.Deviation;
- using GreenTree.Nachtragsmanagement.Services.Deviation;
- namespace GreenTree.Nachtragsmanagement.Web
- {
- // Note: For instructions on enabling IIS6 or IIS7 classic mode,
- // visit http://go.microsoft.com/?LinkId=9394801
- public class MvcApplication : System.Web.HttpApplication
- {
- protected void Application_Start()
- {
- AreaRegistration.RegisterAllAreas();
- GlobalConfiguration.Configure(WebApiConfig.Register);
- FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
- RouteConfig.RegisterRoutes(RouteTable.Routes);
- BundleConfig.RegisterBundles(BundleTable.Bundles);
-
- ModelBinders.Binders.DefaultBinder = new DevExpress.Web.Mvc.DevExpressEditorsBinder();
- ApplicationContext.InitApplication();
- ApplicationContext.InitPluginRoutes(RouteTable.Routes);
- FunctionConfig.RegisterFunctions();
- FluentValidationModelValidatorProvider.Configure(provider =>
- {
- provider.ValidatorFactory = new AppendixValidatorFactory();
- });
- DevExpress.Web.ASPxWebControl.CallbackError += Application_Error;
- GenerateTestData();
- }
- protected void Application_Error(object sender, EventArgs e)
- {
- Exception exception = System.Web.HttpContext.Current.Server.GetLastError();
- //TODO: Handle Exception
- }
- #region Test
- private void GenerateTestData()
- {
- // Get services
- var dbContext = Singleton<IContainer>.Instance.Resolve<IDbContext>();
- var userService = Singleton<IContainer>.Instance.Resolve<IUserService>();
- var deviationService = Singleton<IContainer>.Instance.Resolve<IDeviationService>();
- // Check if test data is already created
- var isTestDataGeneratedEntity = dbContext.Get<DbContextSpec>().FirstOrDefault(d => d.Name == "IsTestDataGenerated");
- if (isTestDataGeneratedEntity != null && Convert.ToBoolean(isTestDataGeneratedEntity.Value))
- return;
- // Create base data
- var kinds = new []
- {
- new Kind { Shortance = "MK", Description = "Mehrkosten" },
- new Kind { Shortance = "BH", Description = "Behinderung" },
- new Kind { Shortance = "BD", Description = "Bedenken" }
- };
- foreach (var kind in kinds)
- deviationService.InsertKind(kind);
- var disturbances = new[]
- {
- new Disturbance { Description = "RPM" },
- new Disturbance { Description = "RM" },
- new Disturbance { Description = "Stopftechnik" },
- new Disturbance { Description = "Umbauzug" },
- new Disturbance { Description = "Logistik" },
- new Disturbance { Description = "Oberbau" },
- new Disturbance { Description = "Erdbau" },
- new Disturbance { Description = "Kabeltiefbau" },
- new Disturbance { Description = "Entwässerung" },
- new Disturbance { Description = "Sonstiges" }
- };
- foreach (var disturbance in disturbances)
- deviationService.InsertDisturbance(disturbance);
- var statuses = new []
- {
- new Status { Description = "Standard" },
- new Status { Description = "Entfällt" },
- new Status { Description = "Strittig" },
- new Status { Description = "Abr. über HLV" }
- };
- foreach (var status in statuses)
- deviationService.InsertStatus(status);
- // Create roles
- var r1 = new Role
- {
- Description = "Administrator",
- Level = 100
- };
- userService.InsertRole(r1);
- var r2 = new Role
- {
- Description = "Kaufmann",
- Level = 10
- };
- userService.InsertRole(r2);
- var r3 = new Role
- {
- Description = "Nachtragsmanager",
- Level = 10
- };
- userService.InsertRole(r3);
- // Create users
- var u1 = new User
- {
- Forename = "Arne",
- Lastname = "Diekmann",
- CustomNumber = "a.diekmann",
- MailAddress = "a.diekmann@greentreestudios.de",
- Password = StaticHelper.GetMD5Hash("14595809")
- };
- userService.InsertUser(u1);
- var u2 = new User
- {
- Forename = "Rocco",
- Lastname = "Lavella",
- CustomNumber = "r.lavella",
- MailAddress = "lavella@schweerbau.de",
- Password = StaticHelper.GetMD5Hash("lavella")
- };
- userService.InsertUser(u2);
- var u3 = new User
- {
- Forename = "Kletus",
- Lastname = "Lingemann",
- CustomNumber = "k.lingemann",
- MailAddress = "k.lingemann@schweerbau.de",
- Password = StaticHelper.GetMD5Hash("lingemann")
- };
- userService.InsertUser(u3);
- // Add users to roles
- u1.Roles.Add(r1);
- u2.Roles.Add(r1);
- u3.Roles.Add(r3);
- // Get all functions and add them to the admin role
- var allFunctions = userService.GetAllFunctions();
- r1.SetFunctions(allFunctions);
- userService.UpdateRole(r1);
- // Get all appendix manager function and add them to the apendix manager / merchant role
- var deviationFunctions = allFunctions
- .Where(f => f.Name.StartsWith("Deviation"));
- foreach (var function in deviationFunctions)
- {
- r2.Functions.Add(function);
- r3.Functions.Add(function);
- }
- var appendixFunctions = allFunctions
- .Where(f => f.Name.StartsWith("Appendix"));
- foreach (var function in appendixFunctions)
- {
- r2.Functions.Add(function);
- r3.Functions.Add(function);
- }
- userService.UpdateRole(r2);
- userService.UpdateRole(r3);
- // Create DbContecSpecification object
- var db1 = new DbContextSpec
- {
- Name = "IsTestDataGenerated",
- Value = "True"
- };
- dbContext.Get<DbContextSpec>().Add(db1);
- }
- #endregion
- }
- }
|