@echo off
set project_name=%1
set entity=%2
set filter_name=%3
set "project_path=%~dp0..\.."
set "scripts_path=%~dp0..\Core"
set entity_path=%project_path%\DAL\Models\Entities
set filter_path=%project_path%\DAL\Models\Filters
set repository_path=%project_path%\DAL\Repositories
set controller_path=%project_path%\%project_name%Server\Controllers
set webapicontext_path=%project_path%\DAL\WebApiContext.cs
set serviceExtensions_path=%project_path%\%project_name%Server\Extends\ServiceExtensions4BaseRepository.cs
set controllertestgeneric_path=%project_path%\XUnitDAL.Test\_Shared\Shared_Test_Controller_Generic.cs
set controllertestentity_path=%project_path%\XUnitDAL.Test\Test_Controller_Entity.cs
set controllertestfilter_path=%project_path%\XUnitDAL.Test\Test_Controller_Filter.cs

if not exist "%entity_path%" mkdir "%entity_path%"
if not exist "%filter_path%" mkdir "%filter_path%"
if not exist "%repository_path%" mkdir "%repository_path%"
if not exist "%controller_path%" mkdir "%controller_path%"

IF "%filter_name%"=="" (
  call %scripts_path%\add_repository.bat %entity% >"%repository_path%"\%entity%Repository.cs
  call %scripts_path%\add_controller.bat %entity% %project_name% >"%controller_path%"\%entity%Controller.cs
) ELSE (
if not exist "%filter_path%"\%filter_name%Filter.cs call %scripts_path%\add_filter.bat %filter_name% >"%filter_path%"\%filter_name%Filter.cs
  call %scripts_path%\add_repository_filter.bat %entity% %filter_name% >"%repository_path%"\%entity%Repository.cs
  call %scripts_path%\add_controller_filter.bat %entity% %project_name% %filter_name% >"%controller_path%"\%entity%Controller.cs
)

call %scripts_path%\add_entity.bat %entity% >"%entity_path%"\%entity%.cs
call %scripts_path%\add_WebApiContext.bat %entity% "%webapicontext_path%"
call %scripts_path%\add_serviceExtensions.bat %entity% "%ServiceExtensions_path%"

if exist "%controllertestgeneric_path%" call %scripts_path%\add_CommonTestController.bat %entity% %controllertestgeneric_path%
if exist "%controllertestentity_path%" call %scripts_path%\add_tests_generic.bat %entity% %controllertestentity_path% Controller  
if exist "%controllertestfilter_path%" (
  IF "%filter_name%" neq "" call %scripts_path%\add_tests_generic.bat %entity% %controllertestfilter_path% FilteredListController %filter_name%
)

echo --finished: %2 




