diff --git a/.gitignore b/.gitignore index 34fe99d5..964aaed6 100644 --- a/.gitignore +++ b/.gitignore @@ -397,3 +397,4 @@ FodyWeavers.xsd # should ignore all *.config files besides of (Web or web).config ![Ww]eb.config *applicationhost.config +/Common/CommonConsole diff --git a/LaaProductionWeb/LaaProduction.Cordonel/Data/EOLProgressRepository.cs b/LaaProductionWeb/LaaProduction.Cordonel/Data/EOLProgressRepository.cs index b5e8b497..75b8f5ce 100644 --- a/LaaProductionWeb/LaaProduction.Cordonel/Data/EOLProgressRepository.cs +++ b/LaaProductionWeb/LaaProduction.Cordonel/Data/EOLProgressRepository.cs @@ -15,40 +15,56 @@ this.sqlConnection = sqlConnection; } - public EOLProgressModel Complete(int pcbid, string hostname, Status status) + public EOLProgressModel Complete(int pcbid, string editedBy, Status status) { this.sqlConnection .CreateCommand($@" UPDATE [Cordonel_EOL_Progress] SET [Completed] = @{nameof(status)} - , [CompleteHost] = @{nameof(hostname)} + , [EditedBy] = @{nameof(editedBy)} , [CompleteDate] = GETDATE() WHERE [PcbId] = @{nameof(pcbid)} AND [Completed] IS NULL") .SetParameter(nameof(pcbid), pcbid) - .SetParameter(nameof(hostname), hostname) + .SetParameter(nameof(editedBy), editedBy) .SetParameter(nameof(status), status.ToString()) .ExecuteNonQuery(); return this.Find(pcbid); } - public EOLProgressModel Create(int pcbid, string hostname) + public EOLProgressModel Create(int pcbid, string editedBy) { + const int MAX_LEN_EDITED_BY = 200; + + if (!string.IsNullOrWhiteSpace(editedBy) && editedBy.Length > MAX_LEN_EDITED_BY) + { + editedBy = editedBy.Substring(0, MAX_LEN_EDITED_BY); + } + this.sqlConnection .CreateCommand($@" INSERT - INTO [Cordonel_EOL_Progress] ([PcbId], [AddHost]) - VALUES (@{nameof(pcbid)}, @{nameof(hostname)})") + INTO [Cordonel_EOL_Progress] ([PcbId], [EditedBy]) + VALUES (@{nameof(pcbid)}, @{nameof(editedBy)})") .SetParameter(nameof(pcbid), pcbid) - .SetParameter(nameof(hostname), hostname) + .SetParameter(nameof(editedBy), editedBy) .ExecuteNonQuery(); return this.Find(pcbid); } - public EOLProgressModel Delete(int pcbid) + public EOLProgressModel Delete(int pcbid, string editedBy) { + this.sqlConnection + .CreateCommand($@" + UPDATE [Cordonel_EOL_Progress] + SET [EditedBy] = @{nameof(editedBy)} + WHERE [PcbId] = @{nameof(pcbid)}") + .SetParameter(nameof(editedBy), editedBy) + .SetParameter(nameof(pcbid), pcbid) + .ExecuteNonQuery(); + this.sqlConnection .CreateCommand($@" DELETE FROM [Cordonel_EOL_Progress] @@ -63,23 +79,22 @@ { return this.sqlConnection .CreateCommand($@" - SELECT [Id] -- 0 - , [PcbId] -- 1 - , [RequirementId] -- 2 - , [RequirementChecked] -- 3 - , [PasswordFileInstalled] -- 4 - , [ProductionStatusChecked] -- 5 - , [ParameterizationDone] -- 6 - , [RebootDone] -- 7 - , [StoreConfigurationDone] -- 8 - , [ExportDone] -- 9 - , [RaioCheckId] -- 10 - , [SentinelDate] -- 11 - , [Completed] -- 12 - , [CompleteHost] -- 13 - , [CompleteDate] -- 14 - , [AddHost] -- 15 - , [AddDate] -- 16 + SELECT [Id] -- 0 + , [PcbId] -- 1 + , [AddDate] -- 2 + , [RequirementId] -- 3 + , [RequirementChecked] -- 4 + , [PasswordFileInstalled] -- 5 + , [ProductionStatusChecked] -- 6 + , [ParameterizationDone] -- 7 + , [RebootDone] -- 8 + , [StoreConfigurationDone] -- 9 + , [ExportDone] -- 10 + , [RaioCheckId] -- 11 + , [SentinelDate] -- 12 + , [Completed] -- 13 + , [CompleteDate] -- 14 + , [EditedBy] -- 15 FROM [Cordonel_EOL_Progress] WHERE [PcbId] = @{nameof(pcbid)}") .SetParameter(nameof(pcbid), pcbid) @@ -87,6 +102,7 @@ { Id = reader.GetInt(), PcbId = reader.GetInt(), + AddDate = reader.GetValue(), RequirementId = reader.GetValue(), RequirementChecked = reader.GetString(), PasswordFileInstalled = reader.GetString(), @@ -98,10 +114,8 @@ RaioCheckId = reader.GetValue(), SentinelDate = reader.GetValue(), Completed = reader.GetString(), - CompleteHost = reader.GetString(), CompleteDate = reader.GetValue(), - AddHost = reader.GetString(), - AddDate = reader.GetValue(), + EditedBy = reader.GetString(), }); } @@ -120,8 +134,9 @@ , [ExportDone] = ISNULL([ExportDone] , @{nameof(model.ExportDone)}) , [RaioCheckId] = ISNULL([RaioCheckId] , @{nameof(model.RaioCheckId)}) , [SentinelDate] = ISNULL([SentinelDate] , @{nameof(model.SentinelDate)}) - WHERE [PcbId] = @{nameof(model.PcbId)} - AND [CompleteHost] IS NULL") + , [EditedBy] = ISNULL(@{nameof(model.EditedBy)} , [EditedBy]) + WHERE [PcbId] = @{nameof(model.PcbId)} + AND [Completed] IS NULL") .SetParameter(nameof(model.PcbId), model.PcbId) .SetParameter(nameof(model.RequirementId), model.RequirementId) .SetParameter(nameof(model.RequirementChecked), model.RequirementChecked?.ToString()) @@ -133,6 +148,7 @@ .SetParameter(nameof(model.ExportDone), model.ExportDone?.ToString()) .SetParameter(nameof(model.RaioCheckId), model.RaioCheckId) .SetParameter(nameof(model.SentinelDate), model.SentinelDate) + .SetParameter(nameof(model.EditedBy), model.EditedBy) .ExecuteNonQuery(); return this.Find(model.PcbId); diff --git a/LaaProductionWeb/LaaProduction.Cordonel/Data/Interfaces/IEOLProgressRepository.cs b/LaaProductionWeb/LaaProduction.Cordonel/Data/Interfaces/IEOLProgressRepository.cs index 25e020ab..3068c751 100644 --- a/LaaProductionWeb/LaaProduction.Cordonel/Data/Interfaces/IEOLProgressRepository.cs +++ b/LaaProductionWeb/LaaProduction.Cordonel/Data/Interfaces/IEOLProgressRepository.cs @@ -6,11 +6,11 @@ { EOLProgressModel Find(int pcbid); - EOLProgressModel Create(int pcbid, string hostname); + EOLProgressModel Create(int pcbid, string editedBy); - EOLProgressModel Complete(int pcbid, string hostname, Status status); + EOLProgressModel Complete(int pcbid, string editedBy, Status status); - EOLProgressModel Delete(int pcbid); + EOLProgressModel Delete(int pcbid, string editedBy); EOLProgressModel Update(EOLProgressModel model); } diff --git a/LaaProductionWeb/LaaProduction.Cordonel/EOLProgressService.cs b/LaaProductionWeb/LaaProduction.Cordonel/EOLProgressService.cs index fb5d86e5..74356f6e 100644 --- a/LaaProductionWeb/LaaProduction.Cordonel/EOLProgressService.cs +++ b/LaaProductionWeb/LaaProduction.Cordonel/EOLProgressService.cs @@ -13,23 +13,23 @@ this.eolRepository = eolRepository; } - public EOLProgressModel Complete(int pcbid, string hostname, Status status) + public EOLProgressModel Complete(int pcbid, string editedBy, Status status) { - return this.eolRepository.Complete(pcbid, hostname, status); + return this.eolRepository.Complete(pcbid, editedBy, status); } - public EOLProgressModel Delete(int pcbid) + public EOLProgressModel Delete(int pcbid, string editedBy) { - return this.eolRepository.Delete(pcbid); + return this.eolRepository.Delete(pcbid, editedBy); } - public EOLProgressModel GetOrCreate(int pcbid, string hostname) + public EOLProgressModel GetOrCreate(int pcbid, string editedBy) { var model = this.eolRepository.Find(pcbid); if (model is null) { - model = this.eolRepository.Create(pcbid, hostname); + model = this.eolRepository.Create(pcbid, editedBy); } return model; diff --git a/LaaProductionWeb/LaaProduction.Cordonel/Interfaces/IEOLProgressService.cs b/LaaProductionWeb/LaaProduction.Cordonel/Interfaces/IEOLProgressService.cs index 3a87594c..7c299443 100644 --- a/LaaProductionWeb/LaaProduction.Cordonel/Interfaces/IEOLProgressService.cs +++ b/LaaProductionWeb/LaaProduction.Cordonel/Interfaces/IEOLProgressService.cs @@ -4,12 +4,12 @@ public interface IEOLProgressService { - EOLProgressModel GetOrCreate(int pcbid, string hostname); + EOLProgressModel GetOrCreate(int pcbid, string editedBy); - EOLProgressModel Complete(int pcbid, string hostname, Status status); + EOLProgressModel Complete(int pcbid, string editedBy, Status status); EOLProgressModel Update(EOLProgressModel model); - EOLProgressModel Delete(int pcbid); + EOLProgressModel Delete(int pcbid, string editedBy); } } diff --git a/LaaProductionWeb/LaaProduction.Cordonel/Models/EOLProgressModel.cs b/LaaProductionWeb/LaaProduction.Cordonel/Models/EOLProgressModel.cs index 12c941c8..4236121a 100644 --- a/LaaProductionWeb/LaaProduction.Cordonel/Models/EOLProgressModel.cs +++ b/LaaProductionWeb/LaaProduction.Cordonel/Models/EOLProgressModel.cs @@ -5,6 +5,33 @@ using System; using System.ComponentModel.DataAnnotations; + public class Cordonel_DELETE_EOL_Progress + { + [Range(1, int.MaxValue, ErrorMessage = "The PcbId should not be <= 0")] + public int PcbId { get; set; } + + public string EditedBy { get; set; } + } + + public class Cordonel_GET_EOL_Progress + { + [Range(1, int.MaxValue, ErrorMessage = "The PcbId should not be <= 0")] + public int PcbId { get; set; } + + public string EditedBy { get; set; } + } + + public class Cordonel_POST_EOL_Progress + { + [Range(1, int.MaxValue, ErrorMessage = "The PcbId should not be <= 0")] + public int PcbId { get; set; } + + [Required(AllowEmptyStrings = false, ErrorMessage = "Complete status is required.")] + public Status Status { get; set; } + + public string EditedBy { get; set; } + } + public class EOLProgressModel { public int Id { get; set; } @@ -12,6 +39,8 @@ [Range(1, int.MaxValue, ErrorMessage = "The PcbId should not be <= 0")] public int PcbId { get; set; } + public DateTime? AddDate { get; set; } + public int? RequirementId { get; set; } public Status RequirementChecked { get; set; } @@ -36,11 +65,7 @@ public DateTime? CompleteDate { get; set; } - public string CompleteHost { get; set; } - - public DateTime? AddDate { get; set; } - - public string AddHost { get; set; } + public string EditedBy { get; set; } } public class JsonStatusConverter : JsonConverter diff --git a/LaaProductionWeb/LaaProductionWeb/API/APIExtensions.cs b/LaaProductionWeb/LaaProductionWeb/API/APIExtensions.cs index 76e1c84b..294bbb55 100644 --- a/LaaProductionWeb/LaaProductionWeb/API/APIExtensions.cs +++ b/LaaProductionWeb/LaaProductionWeb/API/APIExtensions.cs @@ -30,7 +30,10 @@ ?.FirstOrDefault() ?.ErrorMessage; - errors[errorKey] = errorMessage; + if (!string.IsNullOrWhiteSpace(errorMessage)) + { + errors[errorKey] = errorMessage; + } } } diff --git a/LaaProductionWeb/LaaProductionWeb/API/Cordonel/EOLProgressController.cs b/LaaProductionWeb/LaaProductionWeb/API/Cordonel/EOLProgressController.cs index 72304855..c2213183 100644 --- a/LaaProductionWeb/LaaProductionWeb/API/Cordonel/EOLProgressController.cs +++ b/LaaProductionWeb/LaaProductionWeb/API/Cordonel/EOLProgressController.cs @@ -25,43 +25,39 @@ } [HttpGet] - [Route("{pcbid}")] - public IHttpActionResult Get([FromUri] int pcbid) + [Route] + public IHttpActionResult Get([FromUri] Cordonel_GET_EOL_Progress model) { - if (pcbid <= 0) + if (!this.ModelState.IsValid) { - this.ModelState.AddModelError(PCBID_KEY, PCBID_ERROR); - return this.BadRequest(); } + else if (string.IsNullOrWhiteSpace(model.EditedBy)) + { + model.EditedBy = HttpContext.Current.Request.UserHostName; + } + + var result = this.eolProgress.GetOrCreate(model.PcbId, model.EditedBy); - var hostname = HttpContext.Current.Request.UserHostName; - var model = this.eolProgress.GetOrCreate(pcbid, hostname); - - return this.Json(model); + return this.Json(result); } [HttpPost] - [Route("{pcbid}/{status}")] - public IHttpActionResult Post([FromUri] int pcbid, [FromUri] string status) + [Route] + public IHttpActionResult Post([FromBody] Cordonel_POST_EOL_Progress model) { - if (pcbid <= 0) + if (!this.ModelState.IsValid) { - this.ModelState.AddModelError(PCBID_KEY, PCBID_ERROR); - return this.BadRequest(); } - else if (string.IsNullOrWhiteSpace(status)) + else if (string.IsNullOrWhiteSpace(model.EditedBy)) { - this.ModelState.AddModelError(nameof(Status), "Status is required."); - - return this.BadRequest(); + model.EditedBy = HttpContext.Current.Request.UserHostName; } - var hostname = HttpContext.Current.Request.UserHostName; - var model = this.eolProgress.Complete(pcbid, hostname, status); + var result = this.eolProgress.Complete(model.PcbId, model.EditedBy, model.Status); - return this.Json(model); + return this.Json(result); } [HttpPut] @@ -72,26 +68,32 @@ { return this.BadRequest(); } + else if (string.IsNullOrWhiteSpace(model.EditedBy)) + { + model.EditedBy = HttpContext.Current.Request.UserHostName; + } - model = this.eolProgress.Update(model); + var result = this.eolProgress.Update(model); - return this.Json(model); + return this.Json(result); } [HttpDelete] - [Route("{pcbid}")] - public IHttpActionResult Delete([FromUri] int pcbid) + [Route] + public IHttpActionResult Delete([FromBody] Cordonel_DELETE_EOL_Progress model) { - if (pcbid <= 0) + if (!this.ModelState.IsValid) { - this.ModelState.AddModelError(PCBID_KEY, PCBID_ERROR); - return this.BadRequest(); } + else if (string.IsNullOrWhiteSpace(model.EditedBy)) + { + model.EditedBy = HttpContext.Current.Request.UserHostName; + } - var model = this.eolProgress.Delete(pcbid); + var result = this.eolProgress.Delete(model.PcbId, model.EditedBy); - return this.Json(model); + return this.Json(result); } protected override JsonResult Json(T content, JsonSerializerSettings serializerSettings, Encoding encoding) diff --git a/LaaProductionWeb/LaaProductionWeb/API/SendController.cs b/LaaProductionWeb/LaaProductionWeb/API/SendController.cs index de1214b4..a1356d06 100644 --- a/LaaProductionWeb/LaaProductionWeb/API/SendController.cs +++ b/LaaProductionWeb/LaaProductionWeb/API/SendController.cs @@ -23,7 +23,7 @@ { response = this.BadRequest(); } - else if (!this.TrySendEmail(model, out string state)) + else if (!this.TrySendEmail(model, out var state)) { response = this.BadRequest(state); }