private BaseResponse SaveChangesInCategoryTree(CategoryNodeDto categoryDto) { Category category = Mapper.Map <Category>(categoryDto); Category categoryEntity = databaseContext.Categories.Where(cat => cat.Id == category.Id).FirstOrDefault(); if (categoryEntity == null) { return(BaseResponse.CreateNotFoundResponse(categoryDto.Id, translationProvider)); } foreach (CategoryNodeDto child in categoryDto.Children) { SaveChangesInCategoryTree(child); } databaseContext.Entry(categoryEntity).State = EntityState.Modified; databaseContext.Entry(categoryEntity).CurrentValues.SetValues(categoryDto); return(BaseResponse.CreateOkResponse(translationProvider)); }
private CategoryNodeDto ConvertToNode(CategoryDto source, IList <CategoryDto> allCategories) { var node = new CategoryNodeDto { Id = source.Id, ParentId = source.ParentId, ParentName = source.ParentName, SiteId = source.SiteId, SiteTitle = source.SiteTitle, Name = source.Name, IsPublic = source.IsPublic, Description = source.Description, Children = new List <CategoryNodeDto>(), }; var sourceChildren = allCategories.Where(c => c.ParentId != null && c.ParentId == source.Id).ToList(); foreach (var child in sourceChildren) { node.Children.Add(ConvertToNode(child, allCategories)); } return(node); }