last works ...

This commit is contained in:
2025-12-21 01:55:44 +03:30
parent 77dec2007f
commit 52aece6322
+33 -12
View File
@@ -531,20 +531,21 @@ namespace xFileService.Providers
// //
// Validate ... // Validate ...
var isValid = !model.IsNullOrDefault() && result =
!model.Name.IsNullOrEmpty() &&
!model.Id.IsNull() && !model.Id.IsNull() &&
!providedForId.IsNull() &&
!model.IsNullOrDefault() &&
!model.Id.IsDefaultGuid() && !model.Id.IsDefaultGuid() &&
!providedForId.IsNull(); !model.Name.IsNullOrEmpty();
if (!isValid) if (!result)
{ {
XException.InvalidArgs.Throw(); XException.InvalidArgs.Throw();
} }
// //
// Check Model Exists ... // Check Model Exists ...
isValid = await FileProvider.IsExists(model.Id); result = await FileProvider.IsExists(model.Id);
if (!isValid) if (!result)
{ {
XException.NotFound.Throw(); XException.NotFound.Throw();
} }
@@ -553,6 +554,20 @@ namespace xFileService.Providers
// Update Model by Retrieving ... // Update Model by Retrieving ...
model = await FileProvider.Get(model.Id); model = await FileProvider.Get(model.Id);
//
// Retrieve all References ...
var references = await GetAllReferences(providedForId);
//
// Check isReferenced or not ...
result = references.Any(r => r.Id == model.Id &&
r.References.Any(rf => rf.ProvidedFor == Provider &&
rf.ReferencedTo == $"{providedForId}"));
if (result)
{
return result;
}
// //
int forIndex = await CountReferences(providedForId); int forIndex = await CountReferences(providedForId);
model.References.Add(new XReference<string> model.References.Add(new XReference<string>
@@ -595,15 +610,21 @@ namespace xFileService.Providers
// //
// Validate ... // Validate ...
// Since other Validations Handled in Calling, we Ignore them here ... // Since other Validations Handled in Calling, we Ignore them here ...
if (model.IsNull() || var result =
reference.IsNullOrDefault() || !model.IsNullOrDefault() &&
(!reference.ProvidedFor.IsNullOrEmpty() && reference.ProvidedFor != Provider)) !model.Id.IsNull() &&
!model.Id.IsDefaultGuid() &&
!reference.IsNullOrDefault() &&
!reference.ReferencedTo.IsNull() &&
reference.ProvidedFor == Provider &&
!reference.ProvidedFor.IsNullOrEmpty();
if (!result)
{ {
XException.InvalidArgs.Throw(); XException.InvalidArgs.Throw();
} }
// //
var result = await AddReference( result = await AddReference(
model: model, model: model,
userInfo: userInfo, userInfo: userInfo,
connectionId: connectionId, connectionId: connectionId,
@@ -670,7 +691,7 @@ namespace xFileService.Providers
var reference = model.References var reference = model.References
.FirstOrDefault(r => r.ProvidedFor == Provider && .FirstOrDefault(r => r.ProvidedFor == Provider &&
r.ReferencedTo == $"{providedForId}"); r.ReferencedTo == $"{providedForId}");
result = !model.IsNullOrDefault(); result = !reference.IsNullOrDefault();
if (!result) if (!result)
{ {
XException.ActionFailed.Throw(); XException.ActionFailed.Throw();
@@ -865,7 +886,7 @@ namespace xFileService.Providers
) )
{ {
// //
var result = $"{GetProvidedID(providedForId, splitter)}{splitter}{providedForId}"; var result = $"{GetProvidedID(providedForId, splitter)}{splitter}{forIndex}";
// //
return result; return result;