From f36c7de4e2d0521cab11916f7ffbf58157167947 Mon Sep 17 00:00:00 2001 From: Souvik Mazumder Date: Mon, 24 Jan 2022 19:52:06 -0500 Subject: [PATCH] fixed bug with updateasync --- .../DataAccess/MainDataAccess.cs | 11 ++++++++++- .../Exceptions/CreateFailedException.cs | 19 +++++++++++++++++++ .../Exceptions/UpdateFailedException.cs | 4 +++- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 Library.Encyclopedia.Entity/Exceptions/CreateFailedException.cs diff --git a/Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs b/Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs index 0145e33..bdc7d83 100644 --- a/Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs +++ b/Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs @@ -165,6 +165,9 @@ async Task
IMainDataAccess.GetAsync(Guid id) #region CREATE public async Task CreateAsync(Main model) { + if (model.RichDescription.Contains("$$$")) + throw new CreateFailedException(CreateFailErrorCode.INVALID_INPUT_SEQUENCE); + // assign a random id model.Id = Guid.NewGuid(); @@ -183,7 +186,7 @@ public async Task CreateAsync(Main model) private Main ReplaceLineBreaks(Main model) { - string searchStartString = "

"; + string searchStartString = "') + 1); + if (string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value)) { newDesc = newDesc.Replace(tag, "
"); @@ -303,6 +309,9 @@ public async Task

UpdateAsync(Guid id, MainUpdateModel model) if (model.RichDescription != null) { + if (model.RichDescription!=null && model.RichDescription.Contains("$$$")) + throw new UpdateFailedException(UpdateFailErrorCode.INVALID_INPUT_SEQUENCE); + entry.RichDescription = model.RichDescription; entry = ReplaceInternalLinks(entry); diff --git a/Library.Encyclopedia.Entity/Exceptions/CreateFailedException.cs b/Library.Encyclopedia.Entity/Exceptions/CreateFailedException.cs new file mode 100644 index 0000000..1fd9049 --- /dev/null +++ b/Library.Encyclopedia.Entity/Exceptions/CreateFailedException.cs @@ -0,0 +1,19 @@ +using EnumsNET; +using System; +using System.ComponentModel; + +namespace Library.Encyclopedia.Entity.Exceptions +{ + public class CreateFailedException : Exception + { + public CreateFailedException(CreateFailErrorCode code) : base(((CreateFailErrorCode)code).AsString(EnumFormat.Description)) + { + } + } + + public enum CreateFailErrorCode + { + [Description("$$$ is not an accepted input")] + INVALID_INPUT_SEQUENCE + } +} \ No newline at end of file diff --git a/Library.Encyclopedia.Entity/Exceptions/UpdateFailedException.cs b/Library.Encyclopedia.Entity/Exceptions/UpdateFailedException.cs index 7bd1aa6..eb04a1e 100644 --- a/Library.Encyclopedia.Entity/Exceptions/UpdateFailedException.cs +++ b/Library.Encyclopedia.Entity/Exceptions/UpdateFailedException.cs @@ -14,6 +14,8 @@ public UpdateFailedException(UpdateFailErrorCode code) : base(((UpdateFailErrorC public enum UpdateFailErrorCode { [Description("Entry not found!")] - EntryNotFound + EntryNotFound, + [Description("$$$ is not an accepted input")] + INVALID_INPUT_SEQUENCE } }