Skip to content

Commit

Permalink
Added delete.
Browse files Browse the repository at this point in the history
  • Loading branch information
mazumdes committed Jan 25, 2022
1 parent f36c7de commit 1f26368
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,23 @@ async Task<Main> IMainDataAccess.GetAsync(Guid id)
{
Main item = await _dbcontext.Main.Include(s => s.Files).Include(s => s.Links).FirstOrDefaultAsync(s => s.Id == id);

// replace links in item
while (item.RichDescription.IndexOf("$$$") != -1)
if (item != null)
{
var startIndex = item.RichDescription.IndexOf("$$$") + 3;
var endIndex = item.RichDescription.Substring(startIndex).IndexOf("$$$");
if (item.RichDescription != null)
{
// replace links in item
while (item.RichDescription.IndexOf("$$$") != -1)
{
var startIndex = item.RichDescription.IndexOf("$$$") + 3;
var endIndex = item.RichDescription.Substring(startIndex).IndexOf("$$$");

var referenceid = item.RichDescription.Substring(startIndex, endIndex);
var referenceid = item.RichDescription.Substring(startIndex, endIndex);

item.RichDescription = item.RichDescription.Replace($"$$${referenceid}$$$", $"<a href=\"{APP_BASE_URL}/{referenceid}\">{item.Links.FirstOrDefault(s => s.ReferenceId.ToString() == referenceid).Description}</a>");
item.RichDescription = item.RichDescription.Replace($"$$${referenceid}$$$", $"<a href=\"{APP_BASE_URL}/{referenceid}\">{item.Links.FirstOrDefault(s => s.ReferenceId.ToString() == referenceid).Description}</a>");
}
}

return item;
}

return item;
Expand Down Expand Up @@ -309,7 +317,7 @@ public async Task<Main> UpdateAsync(Guid id, MainUpdateModel model)

if (model.RichDescription != null)
{
if (model.RichDescription!=null && model.RichDescription.Contains("$$$"))
if (model.RichDescription != null && model.RichDescription.Contains("$$$"))
throw new UpdateFailedException(UpdateFailErrorCode.INVALID_INPUT_SEQUENCE);

entry.RichDescription = model.RichDescription;
Expand Down Expand Up @@ -339,10 +347,11 @@ public async Task<Main> UpdateAsync(Guid id, MainUpdateModel model)
public async Task DeleteAsync(Guid id)
{
// find the entry
var entry = await _dbcontext.Main.FirstOrDefaultAsync(s => s.Id == id);
var entry = await _dbcontext.Main.Include(s => s.Links).FirstOrDefaultAsync(s => s.Id == id);

if (entry != null)
{
if (entry.Links != null && entry.Links.Any()) _dbcontext.Links.RemoveRange(entry.Links);
_dbcontext.Main.Remove(entry);
await _dbcontext.SaveChanges();
}
Expand Down
18 changes: 18 additions & 0 deletions Library.Encyclopedia.Entity/Exceptions/GetFailedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using EnumsNET;
using System;
using System.ComponentModel;

namespace Library.Encyclopedia.Entity.Exceptions
{
public class GetFailedException : Exception
{
public GetFailedException(GetFailErrorCode code) : base(((GetFailErrorCode)code).AsString(EnumFormat.Description))
{
}
}

public enum GetFailErrorCode
{

}
}

0 comments on commit 1f26368

Please sign in to comment.