last ...
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Extensions;
|
||||
using xDataService.Models;
|
||||
using xFileService.Models.Dtos;
|
||||
using xFileService.Models.Entities;
|
||||
|
||||
namespace xFileService.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 XFile 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 XFileDto 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 XFile UpdateReferences(
|
||||
this XFile source,
|
||||
IList<XReference<string>> references,
|
||||
bool forceClean = true
|
||||
)
|
||||
{
|
||||
//
|
||||
XFile 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 XFileDto UpdateReferences(
|
||||
this XFileDto source,
|
||||
IList<XReference<string>> references,
|
||||
bool forceClean = true
|
||||
)
|
||||
{
|
||||
//
|
||||
XFileDto result = source;
|
||||
|
||||
//
|
||||
if (!source.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
result = source;
|
||||
|
||||
//
|
||||
if (forceClean)
|
||||
{
|
||||
result.References = string.Empty;
|
||||
}
|
||||
|
||||
//
|
||||
if (!references.IsNull() &&
|
||||
references.HasChild())
|
||||
{
|
||||
result.References = references.ToXReferenceString();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Extensions;
|
||||
using xFileService.Models.Dtos;
|
||||
using xFileService.Models.Entities;
|
||||
|
||||
namespace xFileService.Extensions
|
||||
{
|
||||
public static class xFileServiceExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Map Global Properties From XFile to XFile Dto ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static XFileDto ToDto(this XFile source)
|
||||
{
|
||||
//
|
||||
XFileDto result = null;
|
||||
|
||||
//
|
||||
if (!source.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
result = new XFileDto();
|
||||
result = result.UpdateData(
|
||||
updateWith: source,
|
||||
propertyBlackList: new List<string>
|
||||
{
|
||||
nameof(XFileDto.Owner),
|
||||
nameof(XFile.Deleted),
|
||||
nameof(XFile.References),
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
//
|
||||
// Preparing List ...
|
||||
if (!source.References.IsNullOrEmpty())
|
||||
{
|
||||
result.References = source.References.ParseXReferenceList<string>();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Dto to Entity Representation ...
|
||||
/// Ignore ID Property ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static XFile FromDto(this XFileDto source)
|
||||
{
|
||||
//
|
||||
var result = new XFile();
|
||||
|
||||
//
|
||||
if (!source.IsNull())
|
||||
{
|
||||
//
|
||||
result = result.UpdateData(
|
||||
updateWith: source,
|
||||
propertyBlackList: new List<string>
|
||||
{
|
||||
nameof(XFile.Deleted),
|
||||
nameof(XFile.References),
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
if (!source.References.IsNull() && source.References.HasChild())
|
||||
{
|
||||
result.References = source.References.ToXReferenceString();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user