blob: 9a24bf69a662f2e11439e43bb4e60a73257d4626 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!/bin/bash
if [ -z "$1" ] || [ -z "$2" ]; then
echo "No name supplied!"
exit
fi
project_name="$1"
feature_name="$2"
features=("${@:3}")
if [ -z features ]; then
features=("string Name")
fi
#=== Add to Data layer
dir="../$project_name/Data"
# Create the Feature.cs DB model class
cat > $dir/$feature_name.cs<< FILE
using System;
namespace $project_name.Data.Models {
public class $feature_name {
$(
for feature in "${features[@]}"; do
echo -e "\r\t\tpublic $feature { get; set; }"
done
)
}
}
FILE
# Add the DbSet of the Feature to DbContext
dbset="public DbSet<$feature_name> ${feature_name}s { get; set; }"
dbcontext_path="$dir/${project_name}Context.cs"
if grep -Fq "DbSet" $dbcontext_path; then
sed -z -i "s/.*DbSet[^\n]*\n/&\t\t$dbset\n/" $dbcontext_path
else
sed -i "11 i \\\t\t$dbset\n" $dbcontext_path
fi
|