Skip to content

Commit

Permalink
Merge pull request #15 from MahdiyarGHD/develop
Browse files Browse the repository at this point in the history
Add support for content add if it doesn't exists on update
  • Loading branch information
Ali-YousefiTelori authored Sep 2, 2023
2 parents 42f4fc7 + 7856388 commit ba49849
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.5</Version>
<Version>0.0.0.7</Version>
<Description>client generated code.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>microservice,Content,Contents,client</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,43 +100,59 @@ public async Task<MessageContract<CategoryContract>> AddContentWithKey(AddConten
return (FailedReasonType.Incorrect, $"This languages are not registered in the content server: {string.Join(", ", notFoundLanguages)}");
}


[HttpPost]
public async Task<MessageContract> UpdateContentWithKey(AddContentWithKeyRequestContract request)
{
var getCategoryResult = await _categorylogic.GetBy(x => x.Key == request.Key, query => query.Include(x => x.Contents).ThenInclude(x => x.Language));
if (getCategoryResult.IsSuccess)
{
if (getCategoryResult.Result.Contents.Any())
var contents = getCategoryResult.Result.Contents;
foreach (var content in contents)
{
var contents = getCategoryResult.Result.Contents;
foreach (var content in contents)
if (request.LanguageData.Any(o => o.Language == content.Language.Name))
{
if (request.LanguageData.Any(o => o.Language == content.Language.Name))
var response = await _contractlogic.Update(new UpdateContentRequestContract
{
var response = await _contractlogic.Update(new UpdateContentRequestContract
{
Id = content.Id,
CategoryId = content.CategoryId,
LanguageId = content.LanguageId,
UniqueIdentity = content.UniqueIdentity,

Data = request.LanguageData.FirstOrDefault(o => o.Language == content.Language.Name).Data
});
Id = content.Id,
CategoryId = content.CategoryId,
LanguageId = content.LanguageId,
UniqueIdentity = content.UniqueIdentity,

if (!response.IsSuccess)
return (FailedReasonType.Unknown, "An error has occured");
Data = request.LanguageData.FirstOrDefault(o => o.Language == content.Language.Name).Data
});

}
if (!response.IsSuccess)
return (FailedReasonType.Unknown, "An error has occured");
}
}

foreach (var languageData in request.LanguageData)
{
if (!contents.Any(o => o.Language.Name == languageData.Language))
{
var language = await _languagelogic.GetBy(o => o.Name == languageData.Language);

if (!language)
continue;

return true;
var response = await _contractlogic.Add(new CreateContentRequestContract
{
CategoryId = getCategoryResult.Result.Id,
LanguageId = language.Result.Id,
UniqueIdentity = language.Result.UniqueIdentity,

Data = languageData.Data
});

if (!response.IsSuccess)
return (FailedReasonType.Unknown, "An error has occured");
}
}

return true;
}

return (FailedReasonType.Incorrect, $"{getCategoryResult.Result.Key} category doesn't exists");
}


}
}

0 comments on commit ba49849

Please sign in to comment.