From 1a89be223de6b7cd465c2a2bc912ca90bc284991 Mon Sep 17 00:00:00 2001 From: Thomas Hounsell Date: Sun, 16 Apr 2017 23:22:48 +0100 Subject: [PATCH] Adjustments to item history --- BuildFeed.Model/Build.cs | 41 +------------------- BuildFeed.Model/BuildDetails.cs | 49 ++++++++++++++++++++++++ BuildFeed.Model/BuildFeed.Model.csproj | 1 + BuildFeed.Model/BuildRepository.cs | 11 +++--- BuildFeed/Controllers/apiController.cs | 13 +++---- BuildFeed/Controllers/frontController.cs | 33 ++++++++-------- BuildFeed/Views/front/editBuild.cshtml | 2 +- 7 files changed, 82 insertions(+), 68 deletions(-) create mode 100644 BuildFeed.Model/BuildDetails.cs diff --git a/BuildFeed.Model/Build.cs b/BuildFeed.Model/Build.cs index 43d7817..3b9d55f 100644 --- a/BuildFeed.Model/Build.cs +++ b/BuildFeed.Model/Build.cs @@ -4,7 +4,6 @@ using System.ComponentModel.DataAnnotations; using System.Globalization; using System.Text; -using System.Web.Mvc; using BuildFeed.Local; using HtmlAgilityPack; using MongoDB.Bson.Serialization.Attributes; @@ -14,7 +13,7 @@ namespace BuildFeed.Model { [DataObject] [BsonIgnoreExtraElements] - public class Build + public class Build : BuildDetails { [Key] [BsonId] @@ -22,29 +21,6 @@ public class Build public long? LegacyId { get; set; } - [@Required] - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_MajorVersion))] - public uint MajorVersion { get; set; } - - [@Required] - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_MinorVersion))] - public uint MinorVersion { get; set; } - - [@Required] - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_BuildNumber))] - public uint Number { get; set; } - - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Revision))] - [DisplayFormat(ConvertEmptyStringToNull = true)] - public uint? Revision { get; set; } - - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_LabString))] - public string Lab { get; set; } - - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_BuildTime))] - [DisplayFormat(ConvertEmptyStringToNull = true, ApplyFormatInEditMode = true, DataFormatString = "{0:yyMMdd-HHmm}")] - public DateTime? BuildTime { get; set; } - [@Required] [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Added))] public DateTime Added { get; set; } @@ -53,19 +29,6 @@ public class Build [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Modified))] public DateTime Modified { get; set; } - [@Required] - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_SourceType))] - [EnumDataType(typeof(TypeOfSource))] - public TypeOfSource SourceType { get; set; } - - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_SourceDetails))] - [AllowHtml] - public string SourceDetails { get; set; } - - [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_LeakDate))] - [DisplayFormat(ConvertEmptyStringToNull = true, ApplyFormatInEditMode = true)] - public DateTime? LeakDate { get; set; } - public string LabUrl { get; private set; } public bool IsLeaked => SourceType == TypeOfSource.PublicRelease || SourceType == TypeOfSource.InternalLeak || SourceType == TypeOfSource.UpdateGDR; @@ -74,7 +37,7 @@ public class Build public string AlternateBuildString { get; private set; } - public List> History { get; set; } + public List> History { get; set; } [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Search_Version))] public ProjectFamily Family diff --git a/BuildFeed.Model/BuildDetails.cs b/BuildFeed.Model/BuildDetails.cs new file mode 100644 index 0000000..b88b6ae --- /dev/null +++ b/BuildFeed.Model/BuildDetails.cs @@ -0,0 +1,49 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Web.Mvc; +using BuildFeed.Local; +using MongoDB.Bson.Serialization.Attributes; + +namespace BuildFeed.Model +{ + [BsonIgnoreExtraElements] + public class BuildDetails + { + [Required] + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_MajorVersion))] + public uint MajorVersion { get; set; } + + [Required] + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_MinorVersion))] + public uint MinorVersion { get; set; } + + [Required] + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_BuildNumber))] + public uint Number { get; set; } + + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Revision))] + [DisplayFormat(ConvertEmptyStringToNull = true)] + public uint? Revision { get; set; } + + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_LabString))] + public string Lab { get; set; } + + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_BuildTime))] + [DisplayFormat(ConvertEmptyStringToNull = true, ApplyFormatInEditMode = true, + DataFormatString = "{0:yyMMdd-HHmm}")] + public DateTime? BuildTime { get; set; } + + [Required] + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_SourceType))] + [EnumDataType(typeof(TypeOfSource))] + public TypeOfSource SourceType { get; set; } + + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_SourceDetails))] + [AllowHtml] + public string SourceDetails { get; set; } + + [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_LeakDate))] + [DisplayFormat(ConvertEmptyStringToNull = true, ApplyFormatInEditMode = true)] + public DateTime? LeakDate { get; set; } + } +} \ No newline at end of file diff --git a/BuildFeed.Model/BuildFeed.Model.csproj b/BuildFeed.Model/BuildFeed.Model.csproj index 196593b..480b6d3 100644 --- a/BuildFeed.Model/BuildFeed.Model.csproj +++ b/BuildFeed.Model/BuildFeed.Model.csproj @@ -91,6 +91,7 @@ + diff --git a/BuildFeed.Model/BuildRepository.cs b/BuildFeed.Model/BuildRepository.cs index 65c060f..c0a5560 100644 --- a/BuildFeed.Model/BuildRepository.cs +++ b/BuildFeed.Model/BuildRepository.cs @@ -316,7 +316,7 @@ public async Task MigrateAddedModifiedToHistory() List builds = await Select(); foreach (Build bd in builds) { - Build item = new Build + BuildDetails item = new BuildDetails { MajorVersion = bd.MajorVersion, MinorVersion = bd.MinorVersion, @@ -326,18 +326,17 @@ public async Task MigrateAddedModifiedToHistory() BuildTime = bd.BuildTime, SourceType = bd.SourceType, LeakDate = bd.LeakDate, - History = null + SourceDetails = bd.SourceDetails }; - item.RegenerateCachedProperties(); if (bd.Added == DateTime.MinValue) { continue; } - bd.History = new List> + bd.History = new List> { - new ItemHistory + new ItemHistory { Type = ItemHistoryType.Added, Time = bd.Added, @@ -350,7 +349,7 @@ public async Task MigrateAddedModifiedToHistory() if (bd.Modified != DateTime.MinValue && bd.Added != bd.Modified) { - bd.History.Add(new ItemHistory + bd.History.Add(new ItemHistory { Type = ItemHistoryType.Edited, Time = bd.Modified, diff --git a/BuildFeed/Controllers/apiController.cs b/BuildFeed/Controllers/apiController.cs index 23c46dd..8a920e7 100644 --- a/BuildFeed/Controllers/apiController.cs +++ b/BuildFeed/Controllers/apiController.cs @@ -74,9 +74,9 @@ public async Task AddWin10Builds(NewBuildPost apiModel) } if (Membership.ValidateUser(apiModel.Username, apiModel.Password) && (Roles.IsUserInRole(apiModel.Username, "Editors") || Roles.IsUserInRole(apiModel.Username, "Administrators"))) { - var generateOldItem = new Func(nb => + var generateOldItem = new Func(nb => { - Build bi = new Build + BuildDetails bi = new BuildDetails { MajorVersion = nb.MajorVersion, MinorVersion = nb.MinorVersion, @@ -85,11 +85,10 @@ public async Task AddWin10Builds(NewBuildPost apiModel) Lab = nb.Lab, BuildTime = nb.BuildTime.HasValue ? DateTime.SpecifyKind(nb.BuildTime.Value, DateTimeKind.Utc) - : null as DateTime? + : null as DateTime?, + SourceType = TypeOfSource.PrivateLeak }; - bi.RegenerateCachedProperties(); - return bi; }); @@ -107,9 +106,9 @@ public async Task AddWin10Builds(NewBuildPost apiModel) Modified = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), SourceType = TypeOfSource.PrivateLeak, - History = new List> + History = new List> { - new ItemHistory + new ItemHistory { Type = ItemHistoryType.Added, Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), diff --git a/BuildFeed/Controllers/frontController.cs b/BuildFeed/Controllers/frontController.cs index c8212e1..94f60af 100644 --- a/BuildFeed/Controllers/frontController.cs +++ b/BuildFeed/Controllers/frontController.cs @@ -413,7 +413,7 @@ public async Task AddBuild(Build build) build.RegenerateCachedProperties(); - Build bi = new Build + BuildDetails bi = new BuildDetails { MajorVersion = build.MajorVersion, MinorVersion = build.MinorVersion, @@ -422,13 +422,14 @@ public async Task AddBuild(Build build) Lab = build.Lab, BuildTime = build.BuildTime.HasValue ? DateTime.SpecifyKind(build.BuildTime.Value, DateTimeKind.Utc) - : null as DateTime? + : null as DateTime?, + SourceType = build.SourceType, + SourceDetails = build.SourceDetails }; - bi.RegenerateCachedProperties(); - build.History = new List> + build.History = new List> { - new ItemHistory + new ItemHistory { Type = ItemHistoryType.Added, Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), @@ -505,7 +506,7 @@ public async Task AddBulk(FormCollection values) }; b.RegenerateCachedProperties(); - Build bi = new Build + BuildDetails bi = new BuildDetails { MajorVersion = b.MajorVersion, MinorVersion = b.MinorVersion, @@ -514,13 +515,14 @@ public async Task AddBulk(FormCollection values) Lab = b.Lab, BuildTime = b.BuildTime.HasValue ? DateTime.SpecifyKind(b.BuildTime.Value, DateTimeKind.Utc) - : null as DateTime? + : null as DateTime?, + SourceType = b.SourceType, + SourceDetails = b.SourceDetails }; - bi.RegenerateCachedProperties(); - b.History = new List> + b.History = new List> { - new ItemHistory + new ItemHistory { Type = ItemHistoryType.Added, Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), @@ -593,7 +595,7 @@ public async Task EditBuild(Guid id, Build build) build.LeakDate = DateTime.SpecifyKind(build.LeakDate.Value, DateTimeKind.Utc); } - Build bi = new Build + BuildDetails bi = new BuildDetails { MajorVersion = build.MajorVersion, MinorVersion = build.MinorVersion, @@ -602,17 +604,18 @@ public async Task EditBuild(Guid id, Build build) Lab = build.Lab, BuildTime = build.BuildTime.HasValue ? DateTime.SpecifyKind(build.BuildTime.Value, DateTimeKind.Utc) - : null as DateTime? + : null as DateTime?, + SourceType = build.SourceType, + SourceDetails = build.SourceDetails }; - bi.RegenerateCachedProperties(); build.History = b.History; if (build.History == null || build.History.Count == 0) { - build.History = new List>(); + build.History = new List>(); } - build.History.Add(new ItemHistory + build.History.Add(new ItemHistory { Type = ItemHistoryType.Edited, Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), diff --git a/BuildFeed/Views/front/editBuild.cshtml b/BuildFeed/Views/front/editBuild.cshtml index 6b424c6..ad449d4 100644 --- a/BuildFeed/Views/front/editBuild.cshtml +++ b/BuildFeed/Views/front/editBuild.cshtml @@ -109,7 +109,7 @@ else
-