Browse Source

Weitere Entity-Typen und Mappings erstellt. Erste Testdaten eingepflegt und Test-Service angelegt.

Arne Diekmann 8 năm trước cách đây
mục cha
commit
103ec362af
24 tập tin đã thay đổi với 531 bổ sung66 xóa
  1. 54 9
      GreenTree.Nachtragsmanagement.Core/Domain/Appendix/Appendix.cs
  2. 27 22
      GreenTree.Nachtragsmanagement.Core/Domain/Deviation/Deviation.cs
  3. 10 0
      GreenTree.Nachtragsmanagement.Core/Domain/Invoice/Invoice.cs
  4. 67 0
      GreenTree.Nachtragsmanagement.Core/Domain/Misc/MailNotification.cs
  5. 16 0
      GreenTree.Nachtragsmanagement.Core/Domain/Misc/NotificationEvent.cs
  6. 16 0
      GreenTree.Nachtragsmanagement.Core/Domain/Misc/NotificationEventType.cs
  7. 3 0
      GreenTree.Nachtragsmanagement.Core/GreenTree.Nachtragsmanagement.Core.csproj
  8. 5 1
      GreenTree.Nachtragsmanagement.Data/AppendixObjectContext.cs
  9. 1 0
      GreenTree.Nachtragsmanagement.Data/GreenTree.Nachtragsmanagement.Data.csproj
  10. 26 0
      GreenTree.Nachtragsmanagement.Data/Mapping/Appendix/AppendixMap.cs
  11. 41 0
      GreenTree.Nachtragsmanagement.Data/Mapping/Deviation/DeviationMap.cs
  12. 16 0
      GreenTree.Nachtragsmanagement.Services/GreenTree.Nachtragsmanagement.Services.csproj
  13. 14 0
      GreenTree.Nachtragsmanagement.Services/Test/DbRelationFormat.cs
  14. 130 0
      GreenTree.Nachtragsmanagement.Services/Test/DbRelationService.cs
  15. 19 0
      GreenTree.Nachtragsmanagement.Services/Test/IDbRelationService.cs
  16. 5 0
      GreenTree.Nachtragsmanagement.Services/packages.config
  17. 20 3
      GreenTree.Nachtragsmanagement.Web.Framework/ApplicationContext.cs
  18. 17 17
      GreenTree.Nachtragsmanagement.Web/Controllers/HomeController.cs
  19. 2 1
      GreenTree.Nachtragsmanagement.Web/Global.asax.cs
  20. 3 2
      GreenTree.Nachtragsmanagement.Web/GreenTree.Nachtragsmanagement.Web.csproj
  21. 15 0
      GreenTree.Nachtragsmanagement.Web/Models/Test/DbRelationModel.cs
  22. 20 10
      GreenTree.Nachtragsmanagement.Web/Views/Home/Index.cshtml
  23. 4 0
      GreenTree.Nachtragsmanagement.Web/Web.config
  24. 0 1
      GreenTree.Nachtragsmanagement.Web/packages.config

+ 54 - 9
GreenTree.Nachtragsmanagement.Core/Domain/Appendix/Appendix.cs

@@ -10,19 +10,27 @@ namespace GreenTree.Nachtragsmanagement.Core.Domain.Appendix
     {
         #region Fields
 
+        /// <summary>
+        /// Categories related to the appendix
+        /// </summary>
         private ICollection<Category> _categories;
 
-        #endregion
+        /// <summary>
+        /// Deviations related to the appendix
+        /// </summary>
+        private ICollection<Deviation.Deviation> _deviations;
 
         /// <summary>
-        /// Id of corresponding site
+        /// Invoices related to the appendix
         /// </summary>
-        public int SiteId { get; set; }
+        private ICollection<Invoice.Invoice> _invoices;
+
+        #endregion
 
         /// <summary>
         /// Customized number for identification
         /// </summary>
-        public int CustomNumber { get; set; }
+        public int? CustomNumber { get; set; }
 
         /// <summary>
         /// The lot
@@ -32,17 +40,17 @@ namespace GreenTree.Nachtragsmanagement.Core.Domain.Appendix
         /// <summary>
         /// Monetary value of all corresponding deviations
         /// </summary>
-        public decimal Value { get; set; }
+        public decimal? Value { get; set; }
 
         /// <summary>
         /// Percentage probalitity
         /// </summary>
-        public decimal Probability { get; set; }
+        public decimal? Probability { get; set; }
 
         /// <summary>
         /// Number of corresponding offer
         /// </summary>
-        public int OfferingNumber { get; set; }
+        public int? OfferingNumber { get; set; }
 
         /// <summary>
         /// Date when corresponding offer was created
@@ -57,7 +65,7 @@ namespace GreenTree.Nachtragsmanagement.Core.Domain.Appendix
         /// <summary>
         /// Value of negotiation
         /// </summary>
-        public decimal NegotiationValue { get; set; }
+        public decimal? NegotiationValue { get; set; }
 
         /// <summary>
         /// Determines if protocol exists
@@ -67,7 +75,7 @@ namespace GreenTree.Nachtragsmanagement.Core.Domain.Appendix
         /// <summary>
         /// Number of the corresponding order
         /// </summary>
-        public int OrderNumber { get; set; }
+        public int? OrderNumber { get; set; }
 
         /// <summary>
         /// Date of the corresponding order
@@ -78,5 +86,42 @@ namespace GreenTree.Nachtragsmanagement.Core.Domain.Appendix
         /// Editable comment
         /// </summary>
         public string Comment { get; set; }
+
+        /// <summary>
+        /// Id of corresponding site
+        /// </summary>
+        public int? SiteId { get; set; }
+
+        /// <summary>
+        /// Corresponding site
+        /// </summary>
+        public Site.Site Site { get; set; }
+
+        /// <summary>
+        /// Categories related to the appendix
+        /// </summary>
+        public virtual ICollection<Category> Categories
+        {
+            get { return _categories ?? ( _categories = new List<Category>()); }
+            protected set { _categories = value; }
+        }
+
+        /// <summary>
+        /// Deviations related to the appendix
+        /// </summary>
+        public virtual ICollection<Deviation.Deviation> Deviations
+        {
+            get { return _deviations ?? ( _deviations = new List<Deviation.Deviation>()); }
+            protected set { _deviations = value; }
+        }
+
+        /// <summary>
+        /// Invoices related to the appendix
+        /// </summary>
+        public virtual ICollection<Invoice.Invoice> Invoices
+        {
+            get { return _invoices ?? (_invoices = new List<Invoice.Invoice>()); }
+            protected set { _invoices = value; }
+        }
     }
 }

+ 27 - 22
GreenTree.Nachtragsmanagement.Core/Domain/Deviation/Deviation.cs

@@ -9,58 +9,63 @@ namespace GreenTree.Nachtragsmanagement.Core.Domain.Deviation
     public class Deviation : BaseEntity
     {
         /// <summary>
-        /// Id of corresponding Appendix
+        /// Customized number for identification
         /// </summary>
-        public int AppendixId { get; set; }
+        public int? CustomNumber { get; set; }
 
         /// <summary>
-        /// Id of the current deviation status
+        /// Date when deviation were created
         /// </summary>
-        public int StatusId { get; set; }
+        public DateTime ReceiptDate { get; set; }
 
         /// <summary>
-        /// Current deviation status
+        /// Editable comment
         /// </summary>
-        public Status Status { get; set; }
+        public string Comment { get; set; }
 
         /// <summary>
-        /// Id of the current deviation disturbance
+        /// Monetary value
         /// </summary>
-        public int DisturbanceId { get; set; }
+        public decimal? Value { get; set; }
 
         /// <summary>
-        /// Current deviation disturbance
+        /// Id of corresponding appendix
         /// </summary>
-        public Disturbance Disturbance { get; set; }
+        public int? AppendixId { get; set; }
 
         /// <summary>
-        /// Id of the current deviation kind
+        /// Corresponding appendix
         /// </summary>
-        public int KindId { get; set; }
+        public Appendix.Appendix Appendix { get; set; }
 
         /// <summary>
-        /// Current deviation kind
+        /// Id of the current deviation status
         /// </summary>
-        public Kind Kind { get; set; }
+        public int? StatusId { get; set; }
 
         /// <summary>
-        /// Customized number for identification
+        /// Current deviation status
         /// </summary>
-        public int CustomNumber { get; set; }
+        public Status Status { get; set; }
 
         /// <summary>
-        /// Date when deviation were created
+        /// Id of the current deviation disturbance
         /// </summary>
-        public DateTime ReceiptDate { get; set; }
+        public int? DisturbanceId { get; set; }
 
         /// <summary>
-        /// Editable comment
+        /// Current deviation disturbance
         /// </summary>
-        public string Comment { get; set; }
+        public Disturbance Disturbance { get; set; }
 
         /// <summary>
-        /// Monetary value
+        /// Id of the current deviation kind
+        /// </summary>
+        public int? KindId { get; set; }
+
+        /// <summary>
+        /// Current deviation kind
         /// </summary>
-        public decimal Value { get; set; }
+        public Kind Kind { get; set; }
     }
 }

+ 10 - 0
GreenTree.Nachtragsmanagement.Core/Domain/Invoice/Invoice.cs

@@ -22,5 +22,15 @@ namespace GreenTree.Nachtragsmanagement.Core.Domain.Invoice
         /// Invoice date
         /// </summary>
         public DateTime Date { get; set; }
+
+        /// <summary>
+        /// Id of the related appendix
+        /// </summary>
+        public int AppendixId { get; set; }
+
+        /// <summary>
+        /// Appendix related to the invoice
+        /// </summary>
+        public Appendix.Appendix Appendix { get; set; }
     }
 }

+ 67 - 0
GreenTree.Nachtragsmanagement.Core/Domain/Misc/MailNotification.cs

@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace GreenTree.Nachtragsmanagement.Core.Domain.Misc
+{
+    public class MailNotification : BaseEntity
+    {
+        #region Fields
+
+
+
+        #endregion
+
+        /// <summary>
+        /// Id of the corresponding NotificationEventType
+        /// </summary>
+        public int NotificationEventTypeId { get; set; }
+
+        /// <summary>
+        /// Corresponding NotificationEventType
+        /// </summary>
+        public NotificationEventType EventType { get; set; }
+
+        /// <summary>
+        /// Id of the corresponding User
+        /// </summary>
+        public int UserId { get; set; }
+
+        /// <summary>
+        /// Corresponding User
+        /// </summary>
+        public User.User User { get; set; }
+
+        /// <summary>
+        /// The cron expression if the notification will be sent by time
+        /// </summary>
+        public string CronExpression { get; set; }
+
+        /// <summary>
+        /// Id of the corresponding NotificationEvent
+        /// </summary>
+        public int NotificationEventId { get; set; }
+
+        /// <summary>
+        /// Corresponding NotificationEvent
+        /// </summary>
+        public NotificationEvent NotificationEvent { get; set; }
+
+        /// <summary>
+        /// Determines if data is daily summarized before notificated
+        /// </summary>
+        public bool IsDailySummary { get; set; }
+
+        /// <summary>
+        /// Determines if data is weekly summarized before notificated
+        /// </summary>
+        public bool IsWeeklySummary { get; set; }
+
+        /// <summary>
+        /// Determines if data is monthly summarized before notificated
+        /// </summary>
+        public bool IsMonthlySummary { get; set; }
+    }
+}

+ 16 - 0
GreenTree.Nachtragsmanagement.Core/Domain/Misc/NotificationEvent.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace GreenTree.Nachtragsmanagement.Core.Domain.Misc
+{
+    public class NotificationEvent : BaseEntity
+    {
+        /// <summary>
+        /// Description
+        /// </summary>
+        public string Description { get; set; }
+    }
+}

+ 16 - 0
GreenTree.Nachtragsmanagement.Core/Domain/Misc/NotificationEventType.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace GreenTree.Nachtragsmanagement.Core.Domain.Misc
+{
+    public class NotificationEventType : BaseEntity
+    {
+        /// <summary>
+        /// Description
+        /// </summary>
+        public string Description { get; set; }
+    }
+}

+ 3 - 0
GreenTree.Nachtragsmanagement.Core/GreenTree.Nachtragsmanagement.Core.csproj

@@ -49,6 +49,9 @@
     <Compile Include="Domain\Deviation\Kind.cs" />
     <Compile Include="Domain\Deviation\Status.cs" />
     <Compile Include="Domain\Invoice\Invoice.cs" />
+    <Compile Include="Domain\Misc\MailNotification.cs" />
+    <Compile Include="Domain\Misc\NotificationEvent.cs" />
+    <Compile Include="Domain\Misc\NotificationEventType.cs" />
     <Compile Include="Domain\Site\Site.cs" />
     <Compile Include="Domain\User\Function.cs" />
     <Compile Include="Domain\User\Role.cs" />

+ 5 - 1
GreenTree.Nachtragsmanagement.Data/AppendixObjectContext.cs

@@ -13,6 +13,7 @@ using GreenTree.Nachtragsmanagement.Core.Domain.Deviation;
 using GreenTree.Nachtragsmanagement.Core.Domain.Invoice;
 using GreenTree.Nachtragsmanagement.Core.Domain.Site;
 using GreenTree.Nachtragsmanagement.Core.Domain.User;
+using GreenTree.Nachtragsmanagement.Data.Mapping.Appendix;
 using GreenTree.Nachtragsmanagement.Data.Mapping.Deviation;
 using GreenTree.Nachtragsmanagement.Data.Mapping.Site;
 using GreenTree.Nachtragsmanagement.Data.Mapping.User;
@@ -67,7 +68,8 @@ namespace GreenTree.Nachtragsmanagement.Data
                 }
             );
 
-            Database.SetInitializer(new CreateDatabaseIfNotExists<AppendixObjectContext>());
+            //Database.SetInitializer(new CreateDatabaseIfNotExists<AppendixObjectContext>());
+            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<AppendixObjectContext>());
 
             Database.CreateIfNotExists();
 
@@ -88,7 +90,9 @@ namespace GreenTree.Nachtragsmanagement.Data
             modelBuilder.Configurations.Add(new StatusMap());
             modelBuilder.Configurations.Add(new KindMap());
             modelBuilder.Configurations.Add(new DisturbanceMap());
+            modelBuilder.Configurations.Add(new DeviationMap());
             modelBuilder.Configurations.Add(new CategoryMap());
+            modelBuilder.Configurations.Add(new AppendixMap());
 
             base.OnModelCreating(modelBuilder);
         }

+ 1 - 0
GreenTree.Nachtragsmanagement.Data/GreenTree.Nachtragsmanagement.Data.csproj

@@ -51,6 +51,7 @@
     <Compile Include="IDbContext.cs" />
     <Compile Include="Mapping\Appendix\AppendixMap.cs" />
     <Compile Include="Mapping\Appendix\CategoryMap.cs" />
+    <Compile Include="Mapping\Deviation\DeviationMap.cs" />
     <Compile Include="Mapping\Deviation\DisturbanceMap.cs" />
     <Compile Include="Mapping\Deviation\KindMap.cs" />
     <Compile Include="Mapping\Deviation\StatusMap.cs" />

+ 26 - 0
GreenTree.Nachtragsmanagement.Data/Mapping/Appendix/AppendixMap.cs

@@ -15,7 +15,33 @@ namespace GreenTree.Nachtragsmanagement.Data.Mapping.Appendix
 
             HasKey(a => a.Id);
 
+            HasOptional(a => a.Site)
+                .WithMany(s => s.Appendices)
+                .HasForeignKey(a => a.SiteId);
 
+            Property(a => a.CustomNumber);
+            Property(a => a.Lot);
+            Property(a => a.Comment);
+            Property(a => a.Value);
+            Property(a => a.Probability);
+            Property(a => a.OfferingNumber);
+            Property(a => a.OfferingDate);
+            Property(a => a.NegotiationDate);
+            Property(a => a.NegotiationValue);
+            Property(a => a.ProtocolExists);
+            Property(a => a.OrderNumber);
+            Property(a => a.OrderDate);
+
+            HasMany(s => s.Categories)
+                .WithMany()
+                .Map(a => a.ToTable("AppendixCategories"));
+
+            HasMany(s => s.Deviations)
+                .WithOptional();
+
+            HasMany(s => s.Invoices)
+                .WithMany()
+                .Map(a => a.ToTable("AppendixInvoices"));
         }
     }
 }

+ 41 - 0
GreenTree.Nachtragsmanagement.Data/Mapping/Deviation/DeviationMap.cs

@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Data.Entity.ModelConfiguration;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace GreenTree.Nachtragsmanagement.Data.Mapping.Deviation
+{
+    public class DeviationMap : EntityTypeConfiguration<Core.Domain.Deviation.Deviation>
+    {
+        public DeviationMap()
+        {
+            ToTable("Deviation");
+
+            HasKey(d => d.Id);
+
+            Property(d => d.Comment);
+            Property(d => d.CustomNumber);
+            Property(d => d.ReceiptDate);
+            Property(d => d.Comment);
+            Property(d => d.Value);
+
+            HasOptional(d => d.Appendix)
+                .WithMany(s => s.Deviations)
+                .HasForeignKey(d => d.AppendixId);
+
+            HasOptional(d => d.Status)
+                .WithMany()
+                .HasForeignKey(d => d.StatusId);
+
+            HasOptional(d => d.Disturbance)
+                .WithMany()
+                .HasForeignKey(d => d.DisturbanceId);
+
+            HasOptional(d => d.Kind)
+                .WithMany()
+                .HasForeignKey(d => d.KindId);
+        }
+    }
+}

+ 16 - 0
GreenTree.Nachtragsmanagement.Services/GreenTree.Nachtragsmanagement.Services.csproj

@@ -30,7 +30,13 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Autofac, Version=4.6.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
+      <HintPath>..\packages\Autofac.4.6.1\lib\net45\Autofac.dll</HintPath>
+    </Reference>
     <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+    <Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />
@@ -44,6 +50,9 @@
     <Compile Include="DbContext\DbContextService.cs" />
     <Compile Include="DbContext\IDbContextService.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Test\DbRelationFormat.cs" />
+    <Compile Include="Test\DbRelationService.cs" />
+    <Compile Include="Test\IDbRelationService.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\GreenTree.Nachtragsmanagement.Core\GreenTree.Nachtragsmanagement.Core.csproj">
@@ -55,5 +64,12 @@
       <Name>GreenTree.Nachtragsmanagement.Data</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <None Include="packages.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Common\" />
+    <Folder Include="User\" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 14 - 0
GreenTree.Nachtragsmanagement.Services/Test/DbRelationFormat.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace GreenTree.Nachtragsmanagement.Services.Test
+{
+    public enum DbRelationFormat
+    {
+        Json = 0,
+        Xml = 1
+    }
+}

+ 130 - 0
GreenTree.Nachtragsmanagement.Services/Test/DbRelationService.cs

@@ -0,0 +1,130 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using GreenTree.Nachtragsmanagement.Core.Domain.Appendix;
+using GreenTree.Nachtragsmanagement.Core.Domain.Deviation;
+using GreenTree.Nachtragsmanagement.Core.Domain.Site;
+using GreenTree.Nachtragsmanagement.Core.Domain.User;
+using GreenTree.Nachtragsmanagement.Data;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
+
+namespace GreenTree.Nachtragsmanagement.Services.Test
+{
+    public class DbRelationService : IDbRelationService
+    {
+        private readonly IDbContext _idbContext;
+
+        public DbRelationService(
+            IDbContext idbContext)
+        {
+            _idbContext = idbContext;
+        }
+
+        #region Testing
+
+        /// <summary>
+        /// Serialize all existing entities of the current DbContext
+        /// </summary>
+        /// <param name="depth">The depth the serialization should dive in.</param>
+        /// <param name="format">The output format.</param>
+        /// <returns>Return all entities either in JSON- or XML-format.</returns>
+        public List<string> GetRelations(int depth, DbRelationFormat format)
+        {
+            var result = new List<string>();
+            var dbContext = (AppendixObjectContext)_idbContext;
+
+            var userList = dbContext.Get<User>().ToList();
+            var deviationList = dbContext.Get<Deviation>().ToList();
+            var siteList = dbContext.Get<Site>().ToList();
+            var appendixList = dbContext.Get<Appendix>().ToList();
+
+            if (format == DbRelationFormat.Json)
+            {
+                result.Add(SerializeObjectJson(userList, depth));
+                result.Add(SerializeObjectJson(deviationList, depth));
+                result.Add(SerializeObjectJson(siteList, depth));
+                result.Add(SerializeObjectJson(appendixList, depth));
+            }
+            else
+                result.Add(String.Empty);
+
+            return result;
+        }
+
+        #endregion
+
+        #region Utilities
+
+        /// <summary>
+        /// Serialize objects using CustomJsonTextWriter
+        /// </summary>
+        /// <param name="obj">The object to be serialized.</param>
+        /// <param name="maxDepth">The maximum depth.</param>
+        public static string SerializeObjectJson(object obj, int maxDepth)
+        {
+            using (var strWriter = new StringWriter())
+            {
+                using (var jsonWriter = new CustomJsonTextWriter(strWriter))
+                {
+                    Func<bool> include = () => jsonWriter.CurrentDepth <= maxDepth;
+                    var resolver = new CustomContractResolver(include);
+                    var serializer = new JsonSerializer
+                    {
+                        ContractResolver = resolver,
+                        Formatting = Formatting.Indented,
+                        ReferenceLoopHandling = ReferenceLoopHandling.Serialize
+                    };
+                    serializer.Serialize(jsonWriter, obj);
+                }
+                return strWriter.ToString();
+            }
+        }
+
+        #endregion
+    }
+
+    public class CustomJsonTextWriter : JsonTextWriter
+    {
+        public CustomJsonTextWriter(TextWriter textWriter) : base(textWriter) { }
+
+        public int CurrentDepth { get; private set; }
+
+        public override void WriteStartObject()
+        {
+            CurrentDepth++;
+            base.WriteStartObject();
+        }
+
+        public override void WriteEndObject()
+        {
+            CurrentDepth--;
+            base.WriteEndObject();
+        }
+    }
+
+    public class CustomContractResolver : DefaultContractResolver
+    {
+        private readonly Func<bool> _includeProperty;
+
+        public CustomContractResolver(Func<bool> includeProperty)
+        {
+            _includeProperty = includeProperty;
+        }
+
+        protected override JsonProperty CreateProperty(
+            MemberInfo member, MemberSerialization memberSerialization)
+        {
+            var property = base.CreateProperty(member, memberSerialization);
+            var shouldSerialize = property.ShouldSerialize;
+            property.ShouldSerialize = obj => _includeProperty() &&
+                                              (shouldSerialize == null ||
+                                               shouldSerialize(obj));
+            return property;
+        }
+    }
+}

+ 19 - 0
GreenTree.Nachtragsmanagement.Services/Test/IDbRelationService.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace GreenTree.Nachtragsmanagement.Services.Test
+{
+    public interface IDbRelationService
+    {
+        /// <summary>
+        /// Serialize all existing entities of the current DbContext
+        /// </summary>
+        /// <param name="depth">The depth the serialization should dive in.</param>
+        /// <param name="format">The output format.</param>
+        /// <returns>Return all entities either in JSON- or XML-format.</returns>
+        List<string> GetRelations(int depth, DbRelationFormat format);
+    }
+}

+ 5 - 0
GreenTree.Nachtragsmanagement.Services/packages.config

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="Autofac" version="4.6.1" targetFramework="net452" />
+  <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
+</packages>

+ 20 - 3
GreenTree.Nachtragsmanagement.Web.Framework/ApplicationContext.cs

@@ -1,12 +1,15 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
+using System.Web.Mvc;
 using Autofac;
 using Autofac.Integration.Mvc;
 using GreenTree.Nachtragsmanagement.Data;
 using GreenTree.Nachtragsmanagement.Services.DbContext;
+using GreenTree.Nachtragsmanagement.Services.Test;
 
 namespace GreenTree.Nachtragsmanagement.Web.Framework
 {
@@ -40,10 +43,15 @@ namespace GreenTree.Nachtragsmanagement.Web.Framework
         #region Fields
 
         /// <summary>
-        /// Returns the application wide container builder
+        /// Returns the application wide app container builder
         /// </summary>
         private static IContainer _appContainer;
 
+        /// <summary>
+        /// Returns the application wide controller container builder
+        /// </summary>
+        private static IContainer _controllerContainer;
+
         #endregion
 
         #region Services
@@ -70,9 +78,9 @@ namespace GreenTree.Nachtragsmanagement.Web.Framework
         #region Initialization
 
         /// <summary>
-        /// Registers all ressources needed by the ApplicationContext
+        /// Registers all service ressources needed by the ApplicationContext
         /// </summary>
-        public static void Init()
+        public static void InitServices()
         {
             var appBuilder = new ContainerBuilder();
 
@@ -81,7 +89,16 @@ namespace GreenTree.Nachtragsmanagement.Web.Framework
                 .As<IDbContext>()
                 .SingleInstance();
 
+            appBuilder
+                .RegisterType<DbRelationService>()
+                .As<IDbRelationService>();
+
+            appBuilder
+                .RegisterControllers(Assembly.GetCallingAssembly());
+
             _appContainer = appBuilder.Build();
+
+            DependencyResolver.SetResolver(new AutofacDependencyResolver(_appContainer));
         }
 
         #endregion

+ 17 - 17
GreenTree.Nachtragsmanagement.Web/Controllers/HomeController.cs

@@ -3,38 +3,38 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.Mvc;
+using GreenTree.Nachtragsmanagement.Services.Test;
 using GreenTree.Nachtragsmanagement.Web.Framework;
+using GreenTree.Nachtragsmanagement.Web.Models.Test;
 using GreenTree.Nachtragsmanagement.Web.Models.User;
+using Newtonsoft.Json;
 
 namespace GreenTree.Nachtragsmanagement.Web.Controllers
 {
     public class HomeController : Controller
     {
-        // GET: Home
-        public ActionResult Index()
+        private readonly IDbRelationService _dbRelationService;
+
+        public HomeController(
+            IDbRelationService dbRelationService)
         {
-            return View("~/Views/Home/Index.cshtml");
+            _dbRelationService = dbRelationService;
         }
 
-        [HttpPost]
-        public ActionResult Index(UserModel model)
+        // GET: Home
+        public ActionResult Index()
         {
-            var userSet = ApplicationContext.Current.DbContextService.GetDbSet<Core.Domain.User.User>();
-            var dbContext = ApplicationContext.Current.DbContextService.GetDbContext();
+            var relations = _dbRelationService.GetRelations(3, DbRelationFormat.Json);
 
-            var newUser = new Core.Domain.User.User
+            var model = new DbRelationModel
             {
-                CustomId = model.CustomId,
-                Forename = model.Forename,
-                Lastname = model.Lastname,
-                MailAddress = model.MailAddress
+                UserJson = relations[0],
+                DeviationJson = relations[1],
+                SiteJson = relations[2],
+                AppendixJson = relations[3]
             };
 
-            userSet.Add(newUser);
-
-            dbContext.SaveChanges();
-
-            return View("~/Views/Home/Index.cshtml");
+            return View("~/Views/Home/Index.cshtml", model);
         }
     }
 }

+ 2 - 1
GreenTree.Nachtragsmanagement.Web/Global.asax.cs

@@ -7,6 +7,7 @@ using System.Web.Mvc;
 using System.Web.Routing;
 using GreenTree.Nachtragsmanagement.Web.Framework;
 using GreenTree.Nachtragsmanagement.Core.Domain;
+using System.Reflection;
 
 namespace GreenTree.Nachtragsmanagement.Web
 {
@@ -25,7 +26,7 @@ namespace GreenTree.Nachtragsmanagement.Web
             
             ModelBinders.Binders.DefaultBinder = new DevExpress.Web.Mvc.DevExpressEditorsBinder();
 
-            ApplicationContext.Init();
+            ApplicationContext.InitServices();
 
             DevExpress.Web.ASPxWebControl.CallbackError += Application_Error;
         }

+ 3 - 2
GreenTree.Nachtragsmanagement.Web/GreenTree.Nachtragsmanagement.Web.csproj

@@ -58,8 +58,8 @@
       <HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
       <Private>True</Private>
     </Reference>
-    <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
-      <HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
+    <Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Data" />
@@ -191,6 +191,7 @@
     <Compile Include="Global.asax.cs">
       <DependentUpon>Global.asax</DependentUpon>
     </Compile>
+    <Compile Include="Models\Test\DbRelationModel.cs" />
     <Compile Include="Models\User\UserModel.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>

+ 15 - 0
GreenTree.Nachtragsmanagement.Web/Models/Test/DbRelationModel.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace GreenTree.Nachtragsmanagement.Web.Models.Test
+{
+    public class DbRelationModel
+    {
+        public string UserJson { get; set; }
+        public string DeviationJson { get; set; }
+        public string SiteJson { get; set; }
+        public string AppendixJson { get; set; }
+    }
+}

+ 20 - 10
GreenTree.Nachtragsmanagement.Web/Views/Home/Index.cshtml

@@ -3,15 +3,25 @@
     Layout = "~/Views/Shared/_Layout.cshtml";
 }
 
-@model GreenTree.Nachtragsmanagement.Web.Models.User.UserModel
+@model GreenTree.Nachtragsmanagement.Web.Models.Test.DbRelationModel
 
-<h2>Benutzer anlegen</h2>
+<h2>Datenbank - Relationen</h2>
 
-@using (Html.BeginForm())
-{
-	<div>@Html.EditorFor(m => m.CustomId)</div>
-	<div>@Html.EditorFor(m => m.Forename)</div>
-	<div>@Html.EditorFor(m => m.Lastname)</div>
-	<div>@Html.EditorFor(m => m.MailAddress)</div>
-	<input type="submit" value="Speichern" />
-}
+<div style="width: auto; padding-top: 8px; border-top: 1px solid black">
+	<div style="float: left">
+		<h6>Users:</h6>
+		@Html.TextAreaFor(m => m.UserJson, new { rows = 50, cols = 60 })
+	</div>
+	<div style="float: left">
+		<h6>Deviations:</h6>
+		@Html.TextAreaFor(m => m.DeviationJson, new { rows = 50, cols = 60 })
+	</div>
+	<div style="float: left">
+		<h6>Sites:</h6>
+		@Html.TextAreaFor(m => m.SiteJson, new { rows = 50, cols = 60 })
+	</div>
+	<div style="float: left">
+		<h6>Appendices:</h6>
+		@Html.TextAreaFor(m => m.AppendixJson, new { rows = 50, cols = 60 })
+	</div>
+</div>

+ 4 - 0
GreenTree.Nachtragsmanagement.Web/Web.config

@@ -111,6 +111,10 @@
         <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
         <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
       </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
+      </dependentAssembly>
     </assemblyBinding>
   </runtime>
   <devExpress>

+ 0 - 1
GreenTree.Nachtragsmanagement.Web/packages.config

@@ -11,5 +11,4 @@
   <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net452" />
   <package id="Microsoft.AspNet.WebPages.Data" version="3.2.3" targetFramework="net452" />
   <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
-  <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net452" />
 </packages>