149 lines
3.9 KiB
C#
149 lines
3.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using xCategoryService.Models.Dtos;
|
|
using xCategoryService.Models.Entities;
|
|
using xCommons.Extensions;
|
|
using xDataService.Extensions;
|
|
using xDataService.Models;
|
|
|
|
namespace xCategoryService.Extensions
|
|
{
|
|
public static class XModelExtensions
|
|
{
|
|
/// <summary>
|
|
/// Extract References of a Model ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <returns></returns>
|
|
public static IList<XReference<string>> GetReferences(
|
|
this XCategory source
|
|
)
|
|
{
|
|
//
|
|
var result = new List<XReference<string>>();
|
|
|
|
//
|
|
if (
|
|
!source.IsNullOrDefault() &&
|
|
!source.References.IsNullOrEmpty()
|
|
)
|
|
{
|
|
//
|
|
result = source.References
|
|
.ParseXReferenceList<string>()
|
|
.ToList();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Extract References of a Model ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <returns></returns>
|
|
public static IList<XReference<string>> GetReferences(
|
|
this XCategoryDto source
|
|
)
|
|
{
|
|
//
|
|
var result = new List<XReference<string>>();
|
|
|
|
//
|
|
if (
|
|
!source.IsNullOrDefault() &&
|
|
!source.References.IsNullOrEmpty()
|
|
)
|
|
{
|
|
//
|
|
result = source.References
|
|
.ParseXReferenceList<string>()
|
|
.ToList();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update a Model's References by Providing References List ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="references"></param>
|
|
/// <param name="forceClean"></param>
|
|
/// <returns></returns>
|
|
public static XCategory UpdateReferences(
|
|
this XCategory source,
|
|
IList<XReference<string>> references,
|
|
bool forceClean = true
|
|
)
|
|
{
|
|
//
|
|
XCategory result = source;
|
|
|
|
//
|
|
if (!source.IsNullOrDefault())
|
|
{
|
|
//
|
|
result = source;
|
|
|
|
//
|
|
if (forceClean)
|
|
{
|
|
result.References = string.Empty;
|
|
}
|
|
|
|
//
|
|
if (!references.IsNull() &&
|
|
references.HasChild())
|
|
{
|
|
result.References = references.ToXReferenceString();
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update a Model's References by Providing References List ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="references"></param>
|
|
/// <param name="forceClean"></param>
|
|
/// <returns></returns>
|
|
public static XCategoryDto UpdateReferences(
|
|
this XCategoryDto source,
|
|
IList<XReference<string>> references,
|
|
bool forceClean = true
|
|
)
|
|
{
|
|
//
|
|
XCategoryDto result = source;
|
|
|
|
//
|
|
if (!source.IsNullOrDefault())
|
|
{
|
|
//
|
|
result = source;
|
|
|
|
//
|
|
if (forceClean)
|
|
{
|
|
result.References = string.Empty;
|
|
}
|
|
|
|
//
|
|
if (!references.IsNull() &&
|
|
references.HasChild())
|
|
{
|
|
result.References = references.ToXReferenceString();
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
} |