Skip to content

Commit b8afdd0

Browse files
committed
minor refactorings
1 parent cc3fcbf commit b8afdd0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+240
-217
lines changed
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using SampleLogMaker.Models;
2+
using TrackerEnabledDbContext.Common.Configuration;
3+
4+
namespace SampleLogMaker.App_Start
5+
{
6+
internal static class AuditConfig
7+
{
8+
internal static void Configure()
9+
{
10+
EntityTrackingConfiguration<Comment>
11+
.PauseTracking();
12+
}
13+
}
14+
}

SampleLogMaker/App_Start/BundleConfig.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Web;
2-
using System.Web.Optimization;
1+
using System.Web.Optimization;
32

43
namespace SampleLogMaker
54
{

SampleLogMaker/App_Start/FilterConfig.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Web;
2-
using System.Web.Mvc;
1+
using System.Web.Mvc;
32

43
namespace SampleLogMaker
54
{

SampleLogMaker/App_Start/RouteConfig.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Web;
5-
using System.Web.Mvc;
1+
using System.Web.Mvc;
62
using System.Web.Routing;
73

84
namespace SampleLogMaker

SampleLogMaker/Constants.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Web;
5-
6-
namespace SampleLogMaker
1+
namespace SampleLogMaker
72
{
83
public static class Constants
94
{

SampleLogMaker/Controllers/AccountController.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Security.Claims;
5-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
62
using System.Web;
73
using System.Web.Mvc;
84
using Microsoft.AspNet.Identity;

SampleLogMaker/Controllers/BlogsController.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Data;
4-
using System.Data.Entity;
5-
using System.Linq;
1+
using System.Data.Entity;
62
using System.Net;
7-
using System.Web;
83
using System.Web.Mvc;
94
using SampleLogMaker.Models;
105
using System.Threading.Tasks;

SampleLogMaker/Controllers/CommentsController.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Data;
4-
using System.Data.Entity;
5-
using System.Linq;
1+
using System.Linq;
62
using System.Net;
7-
using System.Web;
83
using System.Web.Mvc;
94
using SampleLogMaker.Models;
105

SampleLogMaker/Controllers/HomeController.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Web;
5-
using System.Web.Mvc;
1+
using System.Web.Mvc;
62

73
namespace SampleLogMaker.Controllers
84
{

SampleLogMaker/Global.asax.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Web;
5-
using System.Web.Mvc;
1+
using System.Web.Mvc;
62
using System.Web.Optimization;
73
using System.Web.Routing;
4+
using SampleLogMaker.App_Start;
85

96
namespace SampleLogMaker
107
{
@@ -16,6 +13,7 @@ protected void Application_Start()
1613
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
1714
RouteConfig.RegisterRoutes(RouteTable.Routes);
1815
BundleConfig.RegisterBundles(BundleTable.Bundles);
16+
AuditConfig.Configure();
1917
}
2018
}
2119
}

SampleLogMaker/Models/BlogModel.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.ComponentModel.DataAnnotations;
43
using System.ComponentModel.DataAnnotations.Schema;
5-
using System.Linq;
6-
using System.Web;
7-
using System.Web.Mvc;
84

95
namespace SampleLogMaker.Models
106
{

SampleLogMaker/Models/BlogUser.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace SampleLogMaker.Models
2+
{
3+
public class BlogUser
4+
{
5+
public int Id { get; set; }
6+
7+
public string Username { get; set; }
8+
}
9+
}

SampleLogMaker/Models/Comment.cs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class Comment
1212

1313
[Required]
1414
[UIHint("string")]
15+
[SkipTracking]
1516
public string Text { get; set; }
1617

1718
public virtual int ParentBlogId { get; set; }

SampleLogMaker/Models/DbContexts.cs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using Microsoft.AspNet.Identity.EntityFramework;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Data.Entity;
5-
using System.Linq;
6-
using System.Web;
7-
using TrackerEnabledDbContext;
1+
using System.Data.Entity;
82
using TrackerEnabledDbContext.Identity;
93

104
namespace SampleLogMaker.Models
@@ -16,9 +10,10 @@ public ApplicationDbContext()
1610
{
1711
}
1812

19-
2013
public DbSet<Blog> Blogs { get; set; }
2114

2215
public DbSet<Comment> Comments { get; set; }
16+
17+
public DbSet<BlogUser> BlogUsers { get; set; }
2318
}
2419
}

SampleLogMaker/MyMigrations/Configuration.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
namespace SampleLogMaker.MyMigrations
22
{
3-
using System;
4-
using System.Data.Entity;
53
using System.Data.Entity.Migrations;
6-
using System.Linq;
74

85
internal sealed class Configuration : DbMigrationsConfiguration<SampleLogMaker.Models.ApplicationDbContext>
96
{
107
public Configuration()
118
{
129
AutomaticMigrationsEnabled = true;
10+
AutomaticMigrationDataLossAllowed = true;
1311
MigrationsDirectory = @"MyMigrations";
1412
ContextKey = "SampleLogMaker.Models.ApplicationDbContext";
1513
}

SampleLogMaker/Properties/AssemblyInfo.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

54
// General Information about an assembly is controlled through the following

SampleLogMaker/SampleLogMaker.csproj

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
<HintPath>..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>
4646
</Reference>
4747
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
48-
<HintPath>..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.dll</HintPath>
48+
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
4949
<Private>True</Private>
5050
</Reference>
5151
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
52-
<HintPath>..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.SqlServer.dll</HintPath>
52+
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
5353
<Private>True</Private>
5454
</Reference>
5555
<Reference Include="Microsoft.AspNet.Identity.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -163,6 +163,7 @@
163163
</Reference>
164164
</ItemGroup>
165165
<ItemGroup>
166+
<Compile Include="App_Start\AuditConfig.cs" />
166167
<Compile Include="App_Start\BundleConfig.cs" />
167168
<Compile Include="App_Start\FilterConfig.cs" />
168169
<Compile Include="App_Start\RouteConfig.cs" />
@@ -178,6 +179,7 @@
178179
</Compile>
179180
<Compile Include="Models\AccountViewModels.cs" />
180181
<Compile Include="Models\BlogModel.cs" />
182+
<Compile Include="Models\BlogUser.cs" />
181183
<Compile Include="Models\Comment.cs" />
182184
<Compile Include="Models\DbContexts.cs" />
183185
<Compile Include="Models\IdentityModels.cs" />

SampleLogMaker/ViewModels/History.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Web;
53

64
namespace SampleLogMaker.ViewModels
75
{

SampleLogMaker/ViewModels/LogDetail.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Web;
5-
6-
namespace SampleLogMaker.ViewModels
1+
namespace SampleLogMaker.ViewModels
72
{
83
public class LogDetail
94
{

SampleLogMaker/Views/Account/Manage.cshtml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
@using SampleLogMaker.Models;
2-
@using Microsoft.AspNet.Identity;
3-
@{
1+
@{
42
ViewBag.Title = "Manage Account";
53
}
64

SampleLogMaker/Web.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<configSections>
88

99
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
10-
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
10+
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --><!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
1111
<connectionStrings>
1212
<add name="DefaultConnection" connectionString="Data Source=.\sqlexpress;Initial Catalog=SampleLogMaker-dev;Integrated Security=True;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
1313
</connectionStrings>

SampleLogMaker/packages.config

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Antlr" version="3.5.0.2" targetFramework="net45" userInstalled="true" />
4-
<package id="bootstrap" version="3.2.0" targetFramework="net45" userInstalled="true" />
5-
<package id="EntityFramework" version="6.1.1" targetFramework="net45" userInstalled="true" />
6-
<package id="jQuery" version="2.1.1" targetFramework="net45" userInstalled="true" />
7-
<package id="jQuery.Validation" version="1.13.0" targetFramework="net45" userInstalled="true" />
8-
<package id="Microsoft.AspNet.Identity.Core" version="2.1.0" targetFramework="net45" userInstalled="true" />
9-
<package id="Microsoft.AspNet.Identity.EntityFramework" version="2.1.0" targetFramework="net45" userInstalled="true" />
10-
<package id="Microsoft.AspNet.Identity.Owin" version="2.1.0" targetFramework="net45" userInstalled="true" />
11-
<package id="Microsoft.AspNet.Mvc" version="5.2.2" targetFramework="net45" userInstalled="true" />
12-
<package id="Microsoft.AspNet.Razor" version="3.2.2" targetFramework="net45" userInstalled="true" />
13-
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" userInstalled="true" />
14-
<package id="Microsoft.AspNet.WebPages" version="3.2.2" targetFramework="net45" userInstalled="true" />
15-
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.2" targetFramework="net45" userInstalled="true" />
16-
<package id="Microsoft.Owin" version="3.0.0" targetFramework="net45" userInstalled="true" />
17-
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.0" targetFramework="net45" userInstalled="true" />
18-
<package id="Microsoft.Owin.Security" version="3.0.0" targetFramework="net45" userInstalled="true" />
19-
<package id="Microsoft.Owin.Security.Cookies" version="3.0.0" targetFramework="net45" userInstalled="true" />
20-
<package id="Microsoft.Owin.Security.Facebook" version="3.0.0" targetFramework="net45" userInstalled="true" />
21-
<package id="Microsoft.Owin.Security.Google" version="3.0.0" targetFramework="net45" userInstalled="true" />
22-
<package id="Microsoft.Owin.Security.MicrosoftAccount" version="3.0.0" targetFramework="net45" userInstalled="true" />
23-
<package id="Microsoft.Owin.Security.OAuth" version="3.0.0" targetFramework="net45" userInstalled="true" />
24-
<package id="Microsoft.Owin.Security.Twitter" version="3.0.0" targetFramework="net45" userInstalled="true" />
25-
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" userInstalled="true" />
26-
<package id="Modernizr" version="2.8.3" targetFramework="net45" userInstalled="true" />
27-
<package id="Newtonsoft.Json" version="6.0.6" targetFramework="net45" userInstalled="true" />
28-
<package id="Owin" version="1.0" targetFramework="net45" userInstalled="true" />
29-
<package id="Respond" version="1.4.2" targetFramework="net45" userInstalled="true" />
30-
<package id="WebGrease" version="1.6.0" targetFramework="net45" userInstalled="true" />
3+
<package id="Antlr" version="3.5.0.2" targetFramework="net45" />
4+
<package id="bootstrap" version="3.2.0" targetFramework="net45" />
5+
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />
6+
<package id="jQuery" version="2.1.1" targetFramework="net45" />
7+
<package id="jQuery.Validation" version="1.13.0" targetFramework="net45" />
8+
<package id="Microsoft.AspNet.Identity.Core" version="2.1.0" targetFramework="net45" />
9+
<package id="Microsoft.AspNet.Identity.EntityFramework" version="2.1.0" targetFramework="net45" />
10+
<package id="Microsoft.AspNet.Identity.Owin" version="2.1.0" targetFramework="net45" />
11+
<package id="Microsoft.AspNet.Mvc" version="5.2.2" targetFramework="net45" />
12+
<package id="Microsoft.AspNet.Razor" version="3.2.2" targetFramework="net45" />
13+
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" />
14+
<package id="Microsoft.AspNet.WebPages" version="3.2.2" targetFramework="net45" />
15+
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.2" targetFramework="net45" />
16+
<package id="Microsoft.Owin" version="3.0.0" targetFramework="net45" />
17+
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.0" targetFramework="net45" />
18+
<package id="Microsoft.Owin.Security" version="3.0.0" targetFramework="net45" />
19+
<package id="Microsoft.Owin.Security.Cookies" version="3.0.0" targetFramework="net45" />
20+
<package id="Microsoft.Owin.Security.Facebook" version="3.0.0" targetFramework="net45" />
21+
<package id="Microsoft.Owin.Security.Google" version="3.0.0" targetFramework="net45" />
22+
<package id="Microsoft.Owin.Security.MicrosoftAccount" version="3.0.0" targetFramework="net45" />
23+
<package id="Microsoft.Owin.Security.OAuth" version="3.0.0" targetFramework="net45" />
24+
<package id="Microsoft.Owin.Security.Twitter" version="3.0.0" targetFramework="net45" />
25+
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
26+
<package id="Modernizr" version="2.8.3" targetFramework="net45" />
27+
<package id="Newtonsoft.Json" version="6.0.6" targetFramework="net45" />
28+
<package id="Owin" version="1.0" targetFramework="net45" />
29+
<package id="Respond" version="1.4.2" targetFramework="net45" />
30+
<package id="WebGrease" version="1.6.0" targetFramework="net45" />
3131
</packages>
596 Bytes
Binary file not shown.

TrackerEnabledDbContext.Common.Testing/TrackerEnabledDbContext.Common.Testing.csproj

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
<ErrorReport>prompt</ErrorReport>
3535
<WarningLevel>4</WarningLevel>
3636
</PropertyGroup>
37+
<PropertyGroup>
38+
<SignAssembly>true</SignAssembly>
39+
</PropertyGroup>
40+
<PropertyGroup>
41+
<AssemblyOriginatorKeyFile>MyKey.snk</AssemblyOriginatorKeyFile>
42+
</PropertyGroup>
3743
<ItemGroup>
3844
<Reference Include="EntityFramework">
3945
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
@@ -87,6 +93,7 @@
8793
</ItemGroup>
8894
<ItemGroup>
8995
<None Include="App.config" />
96+
<None Include="MyKey.snk" />
9097
<None Include="packages.config" />
9198
</ItemGroup>
9299
<Choose>

TrackerEnabledDbContext.Common/Attributes/SkipTrackingAttribute.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ namespace System.ComponentModel.DataAnnotations
99
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
1010
public class SkipTrackingAttribute : Attribute
1111
{
12-
public SkipTrackingAttribute(bool skipTracking = true)
13-
{
14-
Enabled = skipTracking;
15-
}
16-
17-
public bool Enabled { get; set; }
12+
1813
}
1914
}

TrackerEnabledDbContext.Common/Attributes/TrackChangesAttribute.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ namespace System.ComponentModel.DataAnnotations
99
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
1010
public class TrackChangesAttribute : Attribute
1111
{
12-
public TrackChangesAttribute(bool trackChanges = true)
13-
{
14-
Enabled = trackChanges;
15-
}
16-
17-
public bool Enabled { get; set; }
12+
1813
}
1914
}

TrackerEnabledDbContext.Common/AddedLogDetailsAuditor.cs TrackerEnabledDbContext.Common/Auditors/AddedLogDetailsAuditor.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
using System.Data.Entity.Infrastructure;
33
using TrackerEnabledDbContext.Common.Models;
44

5-
namespace TrackerEnabledDbContext.Common
5+
namespace TrackerEnabledDbContext.Common.Auditors
66
{
77
/// <summary>
88
/// Creates AuditLogDetails for entries added in a previous call to SaveChanges.
99
/// </summary>
10-
public class AddedLogDetailsAuditor : LogDetailsAuditor
10+
internal class AdditionLogDetailsAuditor : ChangeLogDetailsAuditor
1111
{
12-
public AddedLogDetailsAuditor(DbEntityEntry dbEntry, AuditLog log) : base(dbEntry, log)
12+
internal AdditionLogDetailsAuditor(DbEntityEntry dbEntry, AuditLog log) : base(dbEntry, log)
1313
{
1414
}
1515

@@ -18,7 +18,7 @@ public AddedLogDetailsAuditor(DbEntityEntry dbEntry, AuditLog log) : base(dbEntr
1818
/// </summary>
1919
/// <param name="dbEntry"></param>
2020
/// <returns></returns>
21-
protected override EntityState StateOf(DbEntityEntry dbEntry)
21+
protected internal override EntityState StateOf(DbEntityEntry dbEntry)
2222
{
2323
if (dbEntry.State == EntityState.Unchanged)
2424
{

0 commit comments

Comments
 (0)