Skip to content

Commit

Permalink
fixed bug with updateasync
Browse files Browse the repository at this point in the history
  • Loading branch information
mazumdes committed Jan 25, 2022
1 parent c231867 commit f36c7de
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ async Task<Main> IMainDataAccess.GetAsync(Guid id)
#region CREATE
public async Task<Guid> CreateAsync(Main model)
{
if (model.RichDescription.Contains("$$$"))
throw new CreateFailedException(CreateFailErrorCode.INVALID_INPUT_SEQUENCE);

// assign a random id
model.Id = Guid.NewGuid();

Expand All @@ -183,7 +186,7 @@ public async Task<Guid> CreateAsync(Main model)

private Main ReplaceLineBreaks(Main model)
{
string searchStartString = "<p>";
string searchStartString = "<p";
string searchEndString = "</p>";

if (model.RichDescription != null)
Expand Down Expand Up @@ -213,7 +216,10 @@ private Main ReplaceLineBreaks(Main model)
for (int i = 0; i < startIndexes.Count; i++)
{
string tag = model.RichDescription.Substring(startIndexes[i], endIndexes[i] - startIndexes[i] + searchEndString.Length);

string value = model.RichDescription.Substring(startIndexes[i] + searchStartString.Length, endIndexes[i] - startIndexes[i] - +searchStartString.Length);
value = value.Substring(value.IndexOf('>') + 1);

if (string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value))
{
newDesc = newDesc.Replace(tag, "<br>");
Expand Down Expand Up @@ -303,6 +309,9 @@ public async Task<Main> 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);
Expand Down
19 changes: 19 additions & 0 deletions Library.Encyclopedia.Entity/Exceptions/CreateFailedException.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit f36c7de

Please sign in to comment.