Skip to content

Commit

Permalink
Added category update on project update
Browse files Browse the repository at this point in the history
  • Loading branch information
JVerbruggen committed Apr 12, 2021
1 parent d869c19 commit 551d1ad
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions API/Controllers/ProjectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,36 @@ await callToActionOptionService.GetCallToActionOptionFromValueAsync(
}
}

await projectCategoryService.ClearProjectCategories(project);
if(projectResource.Categories != null)
{
ICollection<ProjectCategoryResource> projectCategoryResources = projectResource.Categories;

foreach(ProjectCategoryResource projectCategoryResource in projectCategoryResources)
{
ProjectCategory alreadyExcProjectCategory = await projectCategoryService.GetProjectCategory(project.Id, projectCategoryResource.CategoryId);
if(alreadyExcProjectCategory == null)
{
Category category = await categoryService.FindAsync(projectCategoryResource.CategoryId);

if(category == null)
{
ProblemDetails problem = new ProblemDetails
{
Title = "Failed to update project.",
Detail = "One of the given categories did not exist.",
Instance = "xxx"
};
return BadRequest(problem);
}

ProjectCategory projectCategory = new ProjectCategory(project, category);
await projectCategoryService.AddAsync(projectCategory)
.ConfigureAwait(false);
}
}
}

mapper.Map(projectResource, project);
projectService.Update(project);
projectService.Save();
Expand Down

0 comments on commit 551d1ad

Please sign in to comment.