nl_05
09/27/2024, 2:47 PMnl_05
09/27/2024, 3:01 PMpublic void Handle(ContentSavingNotification notification)
{
try
{
foreach (var node in notification.SavedEntities)
{
if (node.ContentType.Alias.Equals(CourseDetailChild.ModelTypeAlias))
{
string address = node.GetValue<string>("address");
string map = node.GetValue<string>("map");
string fullAddress = null;
// Check if map is not null or empty
if (!string.IsNullOrEmpty(map))
{
try
{
// Try to parse map as JSON
var mapObject = JObject.Parse(map);
fullAddress = mapObject["address"]?["full_address"]?.ToString();
}
catch (Exception ex)
{
// Handle invalid JSON
// Log or handle exception if needed
fullAddress = null;
}
}
var result = _courseAddress.CheckDuplicateAddress(address, map).Result;
if (result == null)
{
CourseAddress model = new CourseAddress()
{
Address = address,
Map = fullAddress
};
_courseAddress.Save(model);
}
}
}
}
catch (Exception ex)
{
_logger.LogError(ex.ToString(), "CourseSaved");
}
}
nl_05
09/27/2024, 3:02 PMpublic async Task Save(CourseAddress model)
{
using (var scope = _scopeProvider.CreateScope(autoComplete: true))
{
var result = await scope.Database.InsertAsync(model);
scope.Complete();
}
}
Ambert
09/28/2024, 11:13 AMcsharp
public void Handle(ContentSavingNotification notification)
{
try
{
foreach (var node in notification.SavedEntities)
{
if (node.ContentType.Alias.Equals(CourseDetailChild.ModelTypeAlias))
{
string address = node.GetValue<string>("address");
string map = node.GetValue<string>("map");
string fullAddress = null;
// Check if map is not null or empty
if (!string.IsNullOrEmpty(map))
{
try
{
// Try to parse map as JSON
var mapObject = JObject.Parse(map);
fullAddress = mapObject["address"]?["full_address"]?.ToString();
}
catch (Exception ex)
{
// Handle invalid JSON
// Log or handle exception if needed
fullAddress = null;
}
}
var result = _courseAddress.CheckDuplicateAddress(address, map).Result;
if (result == null)
{
CourseAddress model = new CourseAddress()
{
Address = address,
Map = fullAddress
};
_courseAddress.Save(model);
}
}
}
}
catch (Exception ex)
{
_logger.LogError(ex.ToString(), "CourseSaved");
}
}
public async Task Save(CourseAddress model)
{
using (var scope = _scopeProvider.CreateScope(autoComplete: true))
{
var result = await scope.Database.InsertAsync(model);
scope.Complete();
}
}