├── .gitattributes
├── .gitignore
├── CommonLibrary
├── CommonLibrary.sln
├── Model
│ ├── App.config
│ ├── BusinessConstants.cs
│ ├── BusinessDbContext.cs
│ ├── Customers
│ │ └── Customer.cs
│ ├── Entity.cs
│ ├── Model.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── packages.config
├── RepositoryLibrary
│ ├── App.config
│ ├── BaseRepository.cs
│ ├── Customer
│ │ └── CustomerRepository.cs
│ ├── IGenericRepository.cs
│ ├── PaymentRepository.cs
│ ├── ProductDictionaryRepository.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── RepositoryLibrary.csproj
│ ├── SupplierRepository.cs
│ └── packages.config
├── RequestModel
│ ├── App.config
│ ├── Customers
│ │ └── CustomerRequestModel.cs
│ ├── PartnerRequestModel.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── RequestHelperModels.cs
│ ├── RequestModel.csproj
│ └── packages.config
├── ServiceLibrary
│ ├── App.config
│ ├── BaseService.cs
│ ├── Customers
│ │ └── CustomerService.cs
│ ├── IBaseService.cs
│ ├── PaymentService.cs
│ ├── ProductDictionaryService.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── ServiceLibrary.csproj
│ ├── SupplierService.cs
│ └── packages.config
└── ViewModel
│ ├── App.config
│ ├── BaseViewModel.cs
│ ├── Customers
│ └── CustomerViewModel.cs
│ ├── DropdownViewModel.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── ViewModel.csproj
│ └── packages.config
├── Commons
├── Commons.sln
└── Commons
│ ├── App.config
│ ├── Commons.csproj
│ ├── Model
│ ├── BusinessDbContext.cs
│ └── Entity.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── Repository
│ ├── BaseRepository.cs
│ └── IGenericRepository.cs
│ ├── RequestModel
│ ├── ExpressionHelper.cs
│ ├── ParameterRebinder.cs
│ ├── ReplaceExpressionVisitor.cs
│ └── RequestHelperModels.cs
│ ├── Service
│ ├── BaseService.cs
│ └── IBaseService.cs
│ ├── Utility
│ └── ExtensionMethods.cs
│ ├── ViewModel
│ ├── BaseViewModel.cs
│ ├── DropdownViewModel.cs
│ └── IsViewable.cs
│ └── packages.config
├── ConsumerApps
├── ApplicationLibrary
│ ├── App.config
│ ├── ApplicationLibrary.csproj
│ ├── BusinessDbContext.cs
│ ├── Migrations
│ │ ├── 201612030350205_StudentDepartment.Designer.cs
│ │ ├── 201612030350205_StudentDepartment.cs
│ │ ├── 201612030350205_StudentDepartment.resx
│ │ ├── 201612040332398_dontknowwhatischagned.Designer.cs
│ │ ├── 201612040332398_dontknowwhatischagned.cs
│ │ ├── 201612040332398_dontknowwhatischagned.resx
│ │ └── Configuration.cs
│ ├── Models
│ │ ├── Departments
│ │ │ ├── Department.cs
│ │ │ ├── DepartmentRequestModel.cs
│ │ │ └── DepartmetnViewModel.cs
│ │ └── Students
│ │ │ ├── Student.cs
│ │ │ ├── StudentRequestModel.cs
│ │ │ └── StudentViewModel.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── packages.config
├── ConsumerApps.sln
├── ConsumerConsoleApp
│ ├── App.config
│ ├── ConsumerConsoleApp.csproj
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── packages.config
├── ConsumerWinFormsApp
│ ├── App.config
│ ├── App.cs
│ ├── Constants.cs
│ ├── ConsumerWinFormsApp.csproj
│ ├── DepartmentForm.Designer.cs
│ ├── DepartmentForm.cs
│ ├── DepartmentForm.resx
│ ├── ExtensionMethods.cs
│ ├── Form1.Designer.cs
│ ├── Form1.cs
│ ├── Form1.resx
│ ├── IGenericForm.cs
│ ├── Program.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ ├── SampleForm.Designer.cs
│ ├── SampleForm.cs
│ ├── SampleForm.resx
│ ├── StudentsForm.Designer.cs
│ ├── StudentsForm.cs
│ ├── StudentsForm.resx
│ ├── UserControls
│ │ ├── UserControl1.Designer.cs
│ │ ├── UserControl1.cs
│ │ └── UserControl1.resx
│ └── packages.config
└── ConsumerWpfApp
│ ├── App.config
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── AppFactory.cs
│ ├── ConsumerWpfApp.csproj
│ ├── ExtensionMethods.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
│ └── packages.config
├── README.md
└── code-coopers.png
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | [Xx]64/
19 | [Xx]86/
20 | [Bb]uild/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 |
85 | # Visual Studio profiler
86 | *.psess
87 | *.vsp
88 | *.vspx
89 | *.sap
90 |
91 | # TFS 2012 Local Workspace
92 | $tf/
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 | *.DotSettings.user
101 |
102 | # JustCode is a .NET coding add-in
103 | .JustCode
104 |
105 | # TeamCity is a build add-in
106 | _TeamCity*
107 |
108 | # DotCover is a Code Coverage Tool
109 | *.dotCover
110 |
111 | # NCrunch
112 | _NCrunch_*
113 | .*crunch*.local.xml
114 | nCrunchTemp_*
115 |
116 | # MightyMoose
117 | *.mm.*
118 | AutoTest.Net/
119 |
120 | # Web workbench (sass)
121 | .sass-cache/
122 |
123 | # Installshield output folder
124 | [Ee]xpress/
125 |
126 | # DocProject is a documentation generator add-in
127 | DocProject/buildhelp/
128 | DocProject/Help/*.HxT
129 | DocProject/Help/*.HxC
130 | DocProject/Help/*.hhc
131 | DocProject/Help/*.hhk
132 | DocProject/Help/*.hhp
133 | DocProject/Help/Html2
134 | DocProject/Help/html
135 |
136 | # Click-Once directory
137 | publish/
138 |
139 | # Publish Web Output
140 | *.[Pp]ublish.xml
141 | *.azurePubxml
142 |
143 | # TODO: Un-comment the next line if you do not want to checkin
144 | # your web deploy settings because they may include unencrypted
145 | # passwords
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # NuGet Packages
150 | *.nupkg
151 | # The packages folder can be ignored because of Package Restore
152 | **/packages/*
153 | # except build/, which is used as an MSBuild target.
154 | !**/packages/build/
155 | # Uncomment if necessary however generally it will be regenerated when needed
156 | #!**/packages/repositories.config
157 | # NuGet v3's project.json files produces more ignoreable files
158 | *.nuget.props
159 | *.nuget.targets
160 |
161 | # Microsoft Azure Build Output
162 | csx/
163 | *.build.csdef
164 |
165 | # Microsoft Azure Emulator
166 | ecf/
167 | rcf/
168 |
169 | # Windows Store app package directory
170 | AppPackages/
171 | BundleArtifacts/
172 |
173 | # Visual Studio cache files
174 | # files ending in .cache can be ignored
175 | *.[Cc]ache
176 | # but keep track of directories ending in .cache
177 | !*.[Cc]ache/
178 |
179 | # Others
180 | ClientBin/
181 | [Ss]tyle[Cc]op.*
182 | ~$*
183 | *~
184 | *.dbmdl
185 | *.dbproj.schemaview
186 | *.pfx
187 | *.publishsettings
188 | node_modules/
189 | orleans.codegen.cs
190 |
191 | # RIA/Silverlight projects
192 | Generated_Code/
193 |
194 | # Backup & report files from converting an old project file
195 | # to a newer Visual Studio version. Backup files are not needed,
196 | # because we have git ;-)
197 | _UpgradeReport_Files/
198 | Backup*/
199 | UpgradeLog*.XML
200 | UpgradeLog*.htm
201 |
202 | # SQL Server files
203 | *.mdf
204 | *.ldf
205 |
206 | # Business Intelligence projects
207 | *.rdl.data
208 | *.bim.layout
209 | *.bim_*.settings
210 |
211 | # Microsoft Fakes
212 | FakesAssemblies/
213 |
214 | # GhostDoc plugin setting file
215 | *.GhostDoc.xml
216 |
217 | # Node.js Tools for Visual Studio
218 | .ntvs_analysis.dat
219 |
220 | # Visual Studio 6 build log
221 | *.plg
222 |
223 | # Visual Studio 6 workspace options file
224 | *.opt
225 |
226 | # Visual Studio LightSwitch build output
227 | **/*.HTMLClient/GeneratedArtifacts
228 | **/*.DesktopClient/GeneratedArtifacts
229 | **/*.DesktopClient/ModelManifest.xml
230 | **/*.Server/GeneratedArtifacts
231 | **/*.Server/ModelManifest.xml
232 | _Pvt_Extensions
233 |
234 | # LightSwitch generated files
235 | GeneratedArtifacts/
236 | ModelManifest.xml
237 |
238 | # Paket dependency manager
239 | .paket/paket.exe
240 |
241 | # FAKE - F# Make
242 | .fake/
243 | *.nuspec
244 |
--------------------------------------------------------------------------------
/CommonLibrary/CommonLibrary.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{1FFB3CF0-056D-47E0-8335-F46DC10742E5}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RepositoryLibrary", "RepositoryLibrary\RepositoryLibrary.csproj", "{D3A9070F-7560-40EF-BFFA-0A3AFB774D2A}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RequestModel", "RequestModel\RequestModel.csproj", "{45855334-9412-42A4-9547-6513BAE7EF19}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ViewModel", "ViewModel\ViewModel.csproj", "{1D96EABD-3D0C-499E-9531-EF2BD46F1600}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceLibrary", "ServiceLibrary\ServiceLibrary.csproj", "{78F59332-694B-40AA-BEA5-B028B659C8D9}"
15 | EndProject
16 | Global
17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
18 | Debug|Any CPU = Debug|Any CPU
19 | Release|Any CPU = Release|Any CPU
20 | EndGlobalSection
21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
22 | {1FFB3CF0-056D-47E0-8335-F46DC10742E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {1FFB3CF0-056D-47E0-8335-F46DC10742E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {1FFB3CF0-056D-47E0-8335-F46DC10742E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {1FFB3CF0-056D-47E0-8335-F46DC10742E5}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {D3A9070F-7560-40EF-BFFA-0A3AFB774D2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {D3A9070F-7560-40EF-BFFA-0A3AFB774D2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {D3A9070F-7560-40EF-BFFA-0A3AFB774D2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {D3A9070F-7560-40EF-BFFA-0A3AFB774D2A}.Release|Any CPU.Build.0 = Release|Any CPU
30 | {45855334-9412-42A4-9547-6513BAE7EF19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31 | {45855334-9412-42A4-9547-6513BAE7EF19}.Debug|Any CPU.Build.0 = Debug|Any CPU
32 | {45855334-9412-42A4-9547-6513BAE7EF19}.Release|Any CPU.ActiveCfg = Release|Any CPU
33 | {45855334-9412-42A4-9547-6513BAE7EF19}.Release|Any CPU.Build.0 = Release|Any CPU
34 | {1D96EABD-3D0C-499E-9531-EF2BD46F1600}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35 | {1D96EABD-3D0C-499E-9531-EF2BD46F1600}.Debug|Any CPU.Build.0 = Debug|Any CPU
36 | {1D96EABD-3D0C-499E-9531-EF2BD46F1600}.Release|Any CPU.ActiveCfg = Release|Any CPU
37 | {1D96EABD-3D0C-499E-9531-EF2BD46F1600}.Release|Any CPU.Build.0 = Release|Any CPU
38 | {78F59332-694B-40AA-BEA5-B028B659C8D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39 | {78F59332-694B-40AA-BEA5-B028B659C8D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
40 | {78F59332-694B-40AA-BEA5-B028B659C8D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
41 | {78F59332-694B-40AA-BEA5-B028B659C8D9}.Release|Any CPU.Build.0 = Release|Any CPU
42 | EndGlobalSection
43 | GlobalSection(SolutionProperties) = preSolution
44 | HideSolutionNode = FALSE
45 | EndGlobalSection
46 | EndGlobal
47 |
--------------------------------------------------------------------------------
/CommonLibrary/Model/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/CommonLibrary/Model/BusinessConstants.cs:
--------------------------------------------------------------------------------
1 | namespace Model
2 | {
3 | public enum CustomerType
4 | {
5 | Registered, Unregistered
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/CommonLibrary/Model/BusinessDbContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Data.Entity;
3 | using System.Linq;
4 | using Model.Customers;
5 |
6 | namespace Model
7 | {
8 | public class BusinessDbContext : DbContext
9 | {
10 | public BusinessDbContext() : base("DefaultConnection")
11 | {
12 | }
13 |
14 | public override int SaveChanges()
15 | {
16 | var dbEntityEntries = ChangeTracker.Entries().Where(x => x.Entity is Entity);
17 | foreach (var entry in dbEntityEntries)
18 | {
19 | var entity = (Entity)entry.Entity;
20 | entity.Modified = DateTime.Now;
21 | }
22 |
23 | return base.SaveChanges();
24 | }
25 |
26 | public static BusinessDbContext Create()
27 | {
28 | return new BusinessDbContext();
29 | }
30 |
31 | // tables go here
32 |
33 | ///
34 | /// Gets or sets the customers.
35 | ///
36 | ///
37 | /// The customers.
38 | ///
39 | public DbSet Customers { get; set; }
40 | }
41 | }
--------------------------------------------------------------------------------
/CommonLibrary/Model/Customers/Customer.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations;
2 | using System.ComponentModel.DataAnnotations.Schema;
3 |
4 | namespace Model.Customers
5 | {
6 | public class Customer : Entity
7 | {
8 | [Required]
9 | [StringLength(100)]
10 | [Index("IX_MembershipCardNo")]
11 | public string MembershipCardNo { get; set; }
12 |
13 | [Required]
14 | [Index("IX_CustomerName")]
15 | [StringLength(100)]
16 | public string Name { get; set; }
17 |
18 | public string HouseNo { get; set; }
19 | public string RoadNo { get; set; }
20 | public string Area { get; set; }
21 | public string Thana { get; set; }
22 | public string District { get; set; }
23 |
24 | public string Country { get; set; }
25 |
26 | [Required]
27 | [Index("IX_CustomerPhone", IsUnique = true)]
28 | [StringLength(20)]
29 | public string Phone { get; set; }
30 |
31 | [Index("IX_CustomerEmail")]
32 | [StringLength(30)]
33 | public string Email { get; set; }
34 | public int Point { get; set; }
35 | public string Remarks { get; set; }
36 | public bool IsActive { get; set; }
37 | }
38 | }
--------------------------------------------------------------------------------
/CommonLibrary/Model/Entity.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel.DataAnnotations;
3 |
4 | namespace Model
5 | {
6 | public abstract class Entity
7 | {
8 | [Key]
9 | public string Id { get; set; }
10 | [Required]
11 | public DateTime Created { get; set; }
12 | [Required]
13 | public string CreatedBy { get; set; }
14 | [Required]
15 | public DateTime Modified { get; set; }
16 | [Required]
17 | public string ModifiedBy { get; set; }
18 | [Required]
19 | public string CreatedFrom { get; set; }
20 | }
21 |
22 | }
--------------------------------------------------------------------------------
/CommonLibrary/Model/Model.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {1FFB3CF0-056D-47E0-8335-F46DC10742E5}
8 | Library
9 | Properties
10 | Model
11 | Model
12 | v4.6.1
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll
36 | True
37 |
38 |
39 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll
40 | True
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
71 |
--------------------------------------------------------------------------------
/CommonLibrary/Model/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 |
8 | [assembly: AssemblyTitle("Importer.Model")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Importer.Model")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 |
21 | [assembly: ComVisible(false)]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 |
25 | [assembly: Guid("1ffb3cf0-056d-47e0-8335-f46dc10742e5")]
26 |
27 | // Version information for an assembly consists of the following four values:
28 | //
29 | // Major Version
30 | // Minor Version
31 | // Build Number
32 | // Revision
33 | //
34 | // You can specify all the values or you can default the Build and Revision Numbers
35 | // by using the '*' as shown below:
36 | // [assembly: AssemblyVersion("1.0.*")]
37 |
38 | [assembly: AssemblyVersion("1.0.0.0")]
39 | [assembly: AssemblyFileVersion("1.0.0.0")]
--------------------------------------------------------------------------------
/CommonLibrary/Model/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CommonLibrary/RepositoryLibrary/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/CommonLibrary/RepositoryLibrary/BaseRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data.Entity;
4 | using System.Linq;
5 | using System.Linq.Expressions;
6 | using Model;
7 |
8 | namespace RepositoryLibrary
9 | {
10 | public abstract class BaseRepository : IGenericRepository where TEntity : class
11 | {
12 | public BusinessDbContext Db;
13 |
14 | protected BaseRepository(DbContext db)
15 | {
16 | Db = db as BusinessDbContext;
17 | }
18 |
19 | public virtual IQueryable Filter(
20 | Expression> filter = null,
21 | Func, IOrderedQueryable> orderBy = null,
22 | string includeProperties = "")
23 | {
24 | var query = Db.Set().AsQueryable();
25 | if (filter != null)
26 | {
27 | query = query.Where(filter);
28 | }
29 | if (!string.IsNullOrWhiteSpace(includeProperties))
30 | {
31 | var properties = includeProperties.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
32 | foreach (var includeProperty in properties)
33 | {
34 | query = query.Include(includeProperty);
35 | }
36 | }
37 | if (orderBy != null)
38 | {
39 | query = orderBy(query);
40 | }
41 | return query;
42 | }
43 |
44 | public IQueryable Get()
45 | {
46 | var query = Db.Set().AsQueryable();
47 | return query;
48 | }
49 | public TEntity GetById(string id)
50 | {
51 | return Db.Set().Find(id);
52 | }
53 |
54 | public virtual TEntity Add(TEntity entity)
55 | {
56 | return Db.Set().Add(entity);
57 | }
58 |
59 | public virtual IEnumerable Add(IEnumerable entities)
60 | {
61 | var range = Db.Set().AddRange(entities);
62 | return range;
63 | }
64 |
65 | public virtual bool Delete(TEntity entity)
66 | {
67 | var remove = Db.Set().Remove(entity);
68 | return true;
69 | }
70 |
71 | public virtual bool Edit(TEntity entity)
72 | {
73 | Db.Entry(entity).State = EntityState.Modified;
74 | return true;
75 | }
76 |
77 | public virtual bool Save()
78 | {
79 | var changes = Db.SaveChanges();
80 | return changes > 0;
81 | }
82 | }
83 | }
--------------------------------------------------------------------------------
/CommonLibrary/RepositoryLibrary/Customer/CustomerRepository.cs:
--------------------------------------------------------------------------------
1 | using Model;
2 |
3 | namespace RepositoryLibrary.Customer
4 | {
5 | public class CustomerRepository : BaseRepository
6 | {
7 | public CustomerRepository(BusinessDbContext db) : base(db)
8 | {
9 | }
10 | }
11 | }
--------------------------------------------------------------------------------
/CommonLibrary/RepositoryLibrary/IGenericRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Linq.Expressions;
4 |
5 | namespace RepositoryLibrary
6 | {
7 | public interface IGenericRepository where T : class
8 | {
9 | T Add(T entity);
10 | bool Delete(T entity);
11 | bool Edit(T entity);
12 | bool Save();
13 |
14 | IQueryable Filter(
15 | Expression> filter = null,
16 | Func, IOrderedQueryable> orderBy = null,
17 | string includeProperties = "");
18 |
19 | IQueryable Get();
20 | }
21 | }
--------------------------------------------------------------------------------
/CommonLibrary/RepositoryLibrary/PaymentRepository.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Entity;
2 | using Model.Expenses;
3 | using Model;
4 |
5 | namespace RepositoryLibrary
6 | {
7 | public class PaymentRepository : BaseRepository
8 | {
9 | public PaymentRepository(BusinessDbContext db) : base(db)
10 | {
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/CommonLibrary/RepositoryLibrary/ProductDictionaryRepository.cs:
--------------------------------------------------------------------------------
1 | using Model;
2 | using Model.Products;
3 |
4 | namespace RepositoryLibrary
5 | {
6 | public class ProductDictionaryRepository : BaseRepository
7 | {
8 | public ProductDictionaryRepository(BusinessDbContext db) : base(db)
9 | {
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/CommonLibrary/RepositoryLibrary/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("RepositoryLibrary")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("RepositoryLibrary")]
12 | [assembly: AssemblyCopyright("Copyright © 2016")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("d3a9070f-7560-40ef-bffa-0a3afb774d2a")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/CommonLibrary/RepositoryLibrary/RepositoryLibrary.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {D3A9070F-7560-40EF-BFFA-0A3AFB774D2A}
8 | Library
9 | Properties
10 | RepositoryLibrary
11 | RepositoryLibrary
12 | v4.6.1
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll
35 | True
36 |
37 |
38 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll
39 | True
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | {1FFB3CF0-056D-47E0-8335-F46DC10742E5}
60 | Model
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
76 |
--------------------------------------------------------------------------------
/CommonLibrary/RepositoryLibrary/SupplierRepository.cs:
--------------------------------------------------------------------------------
1 | using Model;
2 | using Model.Shops;
3 |
4 | namespace RepositoryLibrary
5 | {
6 | public class SupplierRepository : BaseRepository
7 | {
8 | public SupplierRepository(BusinessDbContext db) : base(db)
9 | {
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/CommonLibrary/RepositoryLibrary/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CommonLibrary/RequestModel/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/CommonLibrary/RequestModel/Customers/CustomerRequestModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq.Expressions;
3 | using Model.Customers;
4 |
5 | namespace RequestModel.Customers
6 | {
7 | public class CustomerRequestModel : RequestModel
8 | {
9 | public CustomerRequestModel(string keyword, string orderBy, string isAscending) : base(keyword, orderBy, isAscending)
10 | {
11 | }
12 |
13 | protected override Expression> GetExpression()
14 | {
15 |
16 | if (!string.IsNullOrWhiteSpace(Keyword))
17 | {
18 | ExpressionObj = x => x.Name.ToLower().Contains(Keyword) || x.HouseNo.ToLower().Contains(Keyword) || x.RoadNo.ToLower().Contains(Keyword) || x.Area.ToLower().Contains(Keyword) || x.Thana.ToLower().Contains(Keyword) || x.District.ToLower().Contains(Keyword) || x.Country.ToLower().Contains(Keyword) || x.Phone.ToLower().Contains(Keyword) || x.Email.ToLower().Contains(Keyword);
19 | }
20 | ExpressionObj = ExpressionObj
21 | .And(GenerateBaseEntityExpression());
22 | return ExpressionObj;
23 | }
24 |
25 |
26 | }
27 | }
--------------------------------------------------------------------------------
/CommonLibrary/RequestModel/PartnerRequestModel.cs:
--------------------------------------------------------------------------------
1 | using Model;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Linq.Expressions;
8 |
9 | namespace RequestModel
10 | {
11 | public class PartnerRequestModel : RequestModelBase
12 | {
13 | public PartnerRequestModel(string keyword, string orderBy, string isAscending) : base(keyword, orderBy, isAscending)
14 | {
15 | }
16 |
17 | protected override Expression> GetExpression()
18 | {
19 | if (!string.IsNullOrWhiteSpace(Keyword))
20 | {
21 | ExpressionObj = x => x.PartnerShopId.ToLower().Contains(Keyword) || x.ShopId.ToLower().Contains(Keyword);
22 | }
23 | if (!string.IsNullOrWhiteSpace(Id))
24 | {
25 | ExpressionObj = ExpressionObj.And(x => x.Id == Id);
26 | }
27 | return ExpressionObj;
28 | }
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/CommonLibrary/RequestModel/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 |
8 | [assembly: AssemblyTitle("Importer.RequestModel")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Importer.RequestModel")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 |
21 | [assembly: ComVisible(false)]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 |
25 | [assembly: Guid("45855334-9412-42a4-9547-6513bae7ef19")]
26 |
27 | // Version information for an assembly consists of the following four values:
28 | //
29 | // Major Version
30 | // Minor Version
31 | // Build Number
32 | // Revision
33 | //
34 | // You can specify all the values or you can default the Build and Revision Numbers
35 | // by using the '*' as shown below:
36 | // [assembly: AssemblyVersion("1.0.*")]
37 |
38 | [assembly: AssemblyVersion("1.0.0.0")]
39 | [assembly: AssemblyFileVersion("1.0.0.0")]
--------------------------------------------------------------------------------
/CommonLibrary/RequestModel/RequestModel.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {45855334-9412-42A4-9547-6513BAE7EF19}
8 | Library
9 | Properties
10 | RequestModel
11 | RequestModel
12 | v4.6.1
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll
36 | True
37 |
38 |
39 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll
40 | True
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | {1FFB3CF0-056D-47E0-8335-F46DC10742E5}
64 | Model
65 |
66 |
67 | {aeba7a9d-5636-4ec8-afd0-bd41171d6023}
68 | Utility
69 |
70 |
71 |
72 |
73 |
80 |
--------------------------------------------------------------------------------
/CommonLibrary/RequestModel/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CommonLibrary/ServiceLibrary/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/CommonLibrary/ServiceLibrary/BaseService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data.Entity;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Model;
7 | using RepositoryLibrary;
8 | using RequestModel;
9 | using ViewModel;
10 |
11 | namespace ServiceLibrary
12 | {
13 | public abstract class BaseService : IBaseService where T : Entity where TRm : RequestModel where TVm : BaseViewModel
14 | {
15 | protected BaseRepository Repository;
16 |
17 | protected BaseService(BaseRepository repository)
18 | {
19 | Repository = repository;
20 | }
21 |
22 | public virtual bool Add(T entity)
23 | {
24 | var add = Repository.Add(entity);
25 | var save = Repository.Save();
26 | return save;
27 | }
28 |
29 |
30 | public bool Delete(T entity)
31 | {
32 | bool deleted = Repository.Delete(entity);
33 | Repository.Save();
34 | return deleted;
35 | }
36 |
37 | public bool Delete(string id)
38 | {
39 | var entity = Repository.Filter(x => x.Id == id).FirstOrDefault();
40 | bool deleted = Repository.Delete(entity);
41 | Repository.Save();
42 | return deleted;
43 | }
44 |
45 | public virtual bool Edit(T entity)
46 | {
47 | bool edit = Repository.Edit(entity);
48 | Repository.Save();
49 | return edit;
50 | }
51 |
52 | public T GetById(string id)
53 | {
54 | return Repository.GetById(id);
55 | }
56 |
57 | public async Task CountAsync(TRm request)
58 | {
59 | var queryable = request.GetOrderedData(Repository.Get());
60 | var count = await queryable.CountAsync();
61 | return count;
62 | }
63 |
64 | public async Task> GetAllAsync()
65 | {
66 | return await Repository.Get().Select(x => (TVm)Activator.CreateInstance(typeof(TVm), x)).ToListAsync();
67 | }
68 |
69 | public async Task,int>> SearchAsync(TRm request)
70 | {
71 | var queryable = request.GetOrderedData(Repository.Get());
72 | int count = queryable.Count();
73 | queryable = request.SkipAndTake(queryable);
74 | var list = await queryable.ToListAsync();
75 | List vms = list.ConvertAll(CreateVmInstance);
76 | return new Tuple, int>(vms,count);
77 | }
78 |
79 | private static TVm CreateVmInstance(T x)
80 | {
81 | return (TVm)Activator.CreateInstance(typeof(TVm), x);
82 | }
83 |
84 | public TVm GetDetail(string id)
85 | {
86 | var model = Repository.GetById(id);
87 | if (model == null)
88 | {
89 | return null;
90 | }
91 | return CreateVmInstance(model);
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/CommonLibrary/ServiceLibrary/Customers/CustomerService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data.Entity;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Vm = ViewModel.Customers.CustomerViewModel;
7 | using Rm = RequestModel.Customers.CustomerRequestModel;
8 | using Repo = RepositoryLibrary.Customer.CustomerRepository;
9 | using M = Model.Customers.Customer;
10 |
11 | namespace ServiceLibrary.Customers
12 | {
13 | public class CustomerService : BaseService
14 | {
15 | public CustomerService(Repo repository) : base(repository)
16 | {
17 |
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/CommonLibrary/ServiceLibrary/IBaseService.cs:
--------------------------------------------------------------------------------
1 | using Model;
2 |
3 | namespace ServiceLibrary
4 | {
5 | public interface IBaseService where T : Entity
6 | {
7 | bool Add(T entity);
8 | bool Delete(T entity);
9 | bool Delete(string id);
10 | bool Edit(T entity);
11 | }
12 | }
--------------------------------------------------------------------------------
/CommonLibrary/ServiceLibrary/PaymentService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data.Entity;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using Model;
8 | using RepositoryLibrary;
9 | using RequestModel;
10 | using ViewModel;
11 | using Vm = ViewModel.ExpenseViewModel;
12 | using Rm = RequestModel.ExpenseRequestModel;
13 | using Repo = RepositoryLibrary.PaymentRepository;
14 | using M = Model.Expense;
15 |
16 | namespace ServiceLibrary
17 | {
18 | public class PaymentService : BaseService
19 | {
20 | private readonly Repo repository;
21 |
22 | public PaymentService(Repo repository) : base(repository)
23 | {
24 | this.repository = repository;
25 | }
26 |
27 | public async Task> GetAllAsync()
28 | {
29 | return await repository.Get().Select(x => new Vm(x)).ToListAsync();
30 | }
31 |
32 | public List GetAll()
33 | {
34 | return repository.Get().Include(y => y.Partner).ToList().ConvertAll(x => new Vm(x)).ToList();
35 | }
36 | public override async Task> SearchAsync(Rm request)
37 | {
38 | IQueryable queryable = request.GetOrderedData(Repository.Get()).Include(y => y.Partner);
39 | queryable = request.SkipAndTake(queryable);
40 | var list = await queryable.ToListAsync();
41 | return list.ConvertAll(x => new Vm(x));
42 | }
43 |
44 | public override Vm GetDetail(string id)
45 | {
46 | var model = Repository.GetById(id);
47 | if (model == null)
48 | {
49 | return null;
50 | }
51 | return new Vm(model);
52 | }
53 |
54 | public override bool Add(M m)
55 | {
56 | bool add = base.Add(m);
57 | var supplierRepository = new SupplierRepository(Repository.Db);
58 | SupplierService supplierService = new SupplierService(supplierRepository);
59 | supplierService.UpdateDue(m.PartnerId);
60 | return true;
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/CommonLibrary/ServiceLibrary/ProductDictionaryService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Vm = ViewModel.ProductDictionaryViewModel;
7 | using Rm = RequestModel.ProductDictionaryRequestModel;
8 | using Repo = RepositoryLibrary.ProductDictionaryRepository;
9 | using M = Model.ProductDictionary;
10 | using Model;
11 | using RepositoryLibrary;
12 | using System.Data.Entity;
13 |
14 | namespace ServiceLibrary
15 | {
16 | public class ProductDictionaryService : BaseService
17 | {
18 | private readonly Repo repository;
19 | public ProductDictionaryService(Repo repository) : base(repository)
20 | {
21 | this.repository = repository;
22 | }
23 |
24 | public async Task> GetAllAsync()
25 | {
26 | return await repository.Get().Select(x => new Vm(x)).ToListAsync();
27 | }
28 |
29 | public List GetAll()
30 | {
31 | return repository.Get().ToList().ConvertAll(x => new Vm(x)).ToList();
32 | }
33 |
34 | public override async Task> SearchAsync(Rm request)
35 | {
36 | var queryable = request.GetOrderedData(Repository.Get());
37 | queryable = request.SkipAndTake(queryable);
38 | var list = await queryable.ToListAsync();
39 | return list.ConvertAll(x => new Vm(x));
40 | }
41 |
42 |
43 | public override Vm GetDetail(string id)
44 | {
45 | var model = Repository.GetById(id);
46 | if (model == null)
47 | {
48 | return null;
49 | }
50 | return new Vm(model);
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/CommonLibrary/ServiceLibrary/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("ServiceLibrary")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("ServiceLibrary")]
12 | [assembly: AssemblyCopyright("Copyright © 2016")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("78f59332-694b-40aa-bea5-b028b659c8d9")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/CommonLibrary/ServiceLibrary/ServiceLibrary.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {78F59332-694B-40AA-BEA5-B028B659C8D9}
8 | Library
9 | Properties
10 | ServiceLibrary
11 | ServiceLibrary
12 | v4.6.1
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 | ..\packages\Aspose.BarCode.7.9.0\lib\net4.5\Aspose.BarCode.dll
35 | True
36 |
37 |
38 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll
39 | True
40 |
41 |
42 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll
43 | True
44 |
45 |
46 | ..\packages\Serilog.2.0.0\lib\net45\Serilog.dll
47 | True
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | {4229B4E8-EA43-4D8A-93E7-A51ADB5E093C}
68 | CacheModel
69 |
70 |
71 | {1FFB3CF0-056D-47E0-8335-F46DC10742E5}
72 | Model
73 |
74 |
75 | {D3A9070F-7560-40EF-BFFA-0A3AFB774D2A}
76 | RepositoryLibrary
77 |
78 |
79 | {45855334-9412-42A4-9547-6513BAE7EF19}
80 | RequestModel
81 |
82 |
83 | {1d96eabd-3d0c-499e-9531-ef2bd46f1600}
84 | ViewModel
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
100 |
--------------------------------------------------------------------------------
/CommonLibrary/ServiceLibrary/SupplierService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data.Entity;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using Model;
8 | using RepositoryLibrary;
9 | using RequestModel;
10 | using ViewModel;
11 | using Vm = ViewModel.PartnerViewModel;
12 | using Rm = RequestModel.PartnerRequsetModel;
13 | using Repo = RepositoryLibrary.SupplierRepository;
14 | using M = Model.Partner;
15 |
16 | namespace ServiceLibrary
17 | {
18 | public class SupplierService : BaseService
19 | {
20 | private readonly Repo repository;
21 |
22 | public SupplierService(Repo repository) : base(repository)
23 | {
24 | this.repository = repository;
25 | }
26 |
27 | public async Task> GetAllAsync()
28 | {
29 | return await repository.Get().Select(x => new Vm(x)).ToListAsync();
30 | }
31 | public List GetAll()
32 | {
33 | return repository.Get().ToList().ConvertAll(x => new Vm(x)).ToList();
34 | }
35 |
36 | public override async Task> SearchAsync(Rm request)
37 | {
38 | IQueryable queryable = request.GetOrderedData(Repository.Get());
39 | queryable = request.SkipAndTake(queryable);
40 | var list = await queryable.ToListAsync();
41 | return list.ConvertAll(x => new Vm(x));
42 | }
43 |
44 | public override Vm GetDetail(string id)
45 | {
46 | var model = Repository.GetById(id);
47 | if (model == null)
48 | {
49 | return null;
50 | }
51 | return new Vm(model);
52 | }
53 |
54 | public async Task GetHistoryAsync(string partnerId)
55 | {
56 | var purchaseRequest = new PurchaseRequestModel("", "Modified", "True") { ParentId = partnerId, Page = -1 };
57 | var purchaseService = new PurchaseService(new PurchaseRepository(repository.Db));
58 | ExpenseRequestModel paymentRequest = new ExpenseRequestModel("", "Modified", "True") { ParentId = partnerId, Page = -1 };
59 | var paymentService = new PaymentService(new PaymentRepository(repository.Db));
60 | List purchases = await purchaseService.SearchAsync(purchaseRequest);
61 | List payments = await paymentService.SearchAsync(paymentRequest);
62 | List histories = new List();
63 | histories.AddRange(purchases.ConvertAll(x => new SupplierHistoryDetailViewModel(x)));
64 | histories.AddRange(payments.ConvertAll(x => new SupplierHistoryDetailViewModel(x)));
65 |
66 | SupplierHistoryViewModel history = new SupplierHistoryViewModel
67 | {
68 | Payments = payments,
69 | Purchases = purchases,
70 | PurchaseTotal = purchases.Sum(x => x.Total),
71 | PaymentTotal = payments.Sum(x => x.Amount),
72 | Histories = histories.OrderBy(x => x.Created).ToList()
73 | };
74 | return history;
75 | }
76 |
77 |
78 |
79 | public bool UpdateDue(string partnerId)
80 | {
81 | IQueryable supplierPurchases = repository.Db.Purchases.Where(x => x.PartnerId == partnerId);
82 | double purchaseTotal = 0;
83 | if (supplierPurchases.Any())
84 | {
85 | purchaseTotal = supplierPurchases
86 | .Select(x => x.Total)
87 | .Sum(x => x != null ? x : 0);
88 | }
89 |
90 |
91 | IQueryable supplierPayments = repository.Db.Expenses.Where(x => x.PartnerId == partnerId);
92 | double paymentTotal = 0;
93 | if (supplierPayments.Any())
94 | {
95 | paymentTotal = supplierPayments
96 | .Select(x => x.Amount)
97 | .Sum(x => x != null ? x : 0);
98 | }
99 |
100 | var entity = repository.Db.Partners.Find(partnerId);
101 | entity.Due = purchaseTotal - paymentTotal;
102 | repository.Db.Entry(entity).State = EntityState.Modified;
103 | repository.Db.SaveChanges();
104 | return true;
105 | }
106 | }
107 | }
--------------------------------------------------------------------------------
/CommonLibrary/ServiceLibrary/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/CommonLibrary/ViewModel/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/CommonLibrary/ViewModel/BaseViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Model;
3 |
4 | namespace ViewModel
5 | {
6 | public abstract class BaseViewModel where T : Entity
7 | {
8 | protected BaseViewModel(Entity x)
9 | {
10 | Id = x.Id;
11 | Created = x.Created;
12 | CreatedBy = x.CreatedBy;
13 | Modified = x.Modified;
14 | ModifiedBy = x.ModifiedBy;
15 | }
16 |
17 | protected BaseViewModel()
18 | {
19 | }
20 |
21 | public string Id { get; set; }
22 |
23 | public DateTime Created { get; set; }
24 |
25 | public string CreatedBy { get; set; }
26 |
27 | public DateTime Modified { get; set; }
28 |
29 | public string ModifiedBy { get; set; }
30 | }
31 | }
--------------------------------------------------------------------------------
/CommonLibrary/ViewModel/Customers/CustomerViewModel.cs:
--------------------------------------------------------------------------------
1 | using Model.Customers;
2 |
3 | namespace ViewModel.Customers
4 | {
5 | public class CustomerViewModel : BaseViewModel
6 | {
7 | public CustomerViewModel(Customer x) : base(x)
8 | {
9 | this.Name = x.Name;
10 | this.HouseNo = x.HouseNo;
11 | this.RoadNo = x.RoadNo;
12 | this.Area = x.Area;
13 | this.Thana = x.Thana;
14 | this.District = x.District;
15 | this.Phone = x.Phone;
16 | this.Email = x.Email;
17 | this.Remarks = x.Remarks;
18 | this.Point = x.Point;
19 | this.MembershipCardNo = x.MembershipCardNo;
20 | this.Country = x.Country;
21 | }
22 |
23 | public string MembershipCardNo { get; set; }
24 |
25 | public string Name { get; set; }
26 |
27 | public string HouseNo { get; set; }
28 | public string RoadNo { get; set; }
29 | public string Area { get; set; }
30 | public string Thana { get; set; }
31 | public string District { get; set; }
32 | public string Country { get; set; }
33 | public string Phone { get; set; }
34 | public string Email { get; set; }
35 | public string Remarks { get; set; }
36 | public int Point { get; set; }
37 |
38 | }
39 | }
--------------------------------------------------------------------------------
/CommonLibrary/ViewModel/DropdownViewModel.cs:
--------------------------------------------------------------------------------
1 | namespace ViewModel
2 | {
3 | public class DropdownViewModel
4 | {
5 | public DropdownViewModel()
6 | {
7 |
8 | }
9 |
10 | public DropdownViewModel(string id, string text)
11 | {
12 | Id = id;
13 | Text = text;
14 | }
15 |
16 | public string Id { get; set; }
17 | public string Text { get; set; }
18 | }
19 | }
--------------------------------------------------------------------------------
/CommonLibrary/ViewModel/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 |
8 | [assembly: AssemblyTitle("Importer.ViewModel")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Importer.ViewModel")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 |
21 | [assembly: ComVisible(false)]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 |
25 | [assembly: Guid("1d96eabd-3d0c-499e-9531-ef2bd46f1600")]
26 |
27 | // Version information for an assembly consists of the following four values:
28 | //
29 | // Major Version
30 | // Minor Version
31 | // Build Number
32 | // Revision
33 | //
34 | // You can specify all the values or you can default the Build and Revision Numbers
35 | // by using the '*' as shown below:
36 | // [assembly: AssemblyVersion("1.0.*")]
37 |
38 | [assembly: AssemblyVersion("1.0.0.0")]
39 | [assembly: AssemblyFileVersion("1.0.0.0")]
--------------------------------------------------------------------------------
/CommonLibrary/ViewModel/ViewModel.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {1D96EABD-3D0C-499E-9531-EF2BD46F1600}
8 | Library
9 | Properties
10 | ViewModel
11 | ViewModel
12 | v4.6.1
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll
36 | True
37 |
38 |
39 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll
40 | True
41 |
42 |
43 | ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | {1FFB3CF0-056D-47E0-8335-F46DC10742E5}
69 | Model
70 |
71 |
72 |
73 |
74 |
81 |
--------------------------------------------------------------------------------
/CommonLibrary/ViewModel/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Commons/Commons.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commons", "Commons\Commons.csproj", "{482131E7-7567-4540-BC11-7125957E7FF5}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {482131E7-7567-4540-BC11-7125957E7FF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {482131E7-7567-4540-BC11-7125957E7FF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {482131E7-7567-4540-BC11-7125957E7FF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {482131E7-7567-4540-BC11-7125957E7FF5}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/Commons/Commons/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Commons/Commons/Commons.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {482131E7-7567-4540-BC11-7125957E7FF5}
8 | Library
9 | Properties
10 | Commons
11 | Commons
12 | v4.5
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 | ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll
35 |
36 |
37 | ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll
38 |
39 |
40 | False
41 | ..\..\ConsumerConsoleApp\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
81 |
--------------------------------------------------------------------------------
/Commons/Commons/Model/BusinessDbContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Data.Entity;
3 | using System.Linq;
4 |
5 | namespace Commons.Model
6 | {
7 | public partial class BusinessDbContext : DbContext
8 | {
9 | public BusinessDbContext() : base("DefaultConnection")
10 | {
11 | }
12 |
13 | public override int SaveChanges()
14 | {
15 | var dbEntityEntries = ChangeTracker.Entries().Where(x => x.Entity is Entity);
16 | foreach (var entry in dbEntityEntries)
17 | {
18 | var entity = (Entity)entry.Entity;
19 | entity.Modified = DateTime.Now;
20 | }
21 |
22 | return base.SaveChanges();
23 | }
24 |
25 | public static BusinessDbContext Create()
26 | {
27 | return new BusinessDbContext();
28 | }
29 |
30 | //tables
31 |
32 | }
33 | }
--------------------------------------------------------------------------------
/Commons/Commons/Model/Entity.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel.DataAnnotations;
3 |
4 | namespace Commons.Model
5 | {
6 | public abstract class Entity
7 | {
8 | [Key]
9 | public string Id { get; set; }
10 |
11 | [Required]
12 | public DateTime Created { get; set; }
13 |
14 | [Required]
15 | public string CreatedBy { get; set; }
16 |
17 | [Required]
18 | public DateTime Modified { get; set; }
19 |
20 | [Required]
21 | public string ModifiedBy { get; set; }
22 |
23 | [Required]
24 | public string CreatedFrom { get; set; }
25 |
26 | [Required]
27 | public string ModifiedFrom { get; set; }
28 |
29 | [Required]
30 | public bool IsDeleted { get; set; }
31 | }
32 |
33 | }
--------------------------------------------------------------------------------
/Commons/Commons/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Commons")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Commons")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("482131e7-7567-4540-bc11-7125957e7ff5")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Commons/Commons/Repository/BaseRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data.Entity;
4 | using System.Linq;
5 | using System.Linq.Expressions;
6 | using Commons.Model;
7 |
8 | namespace Commons.Repository
9 | {
10 | public class BaseRepository : IGenericRepository where TEntity : class
11 | {
12 | public DbContext Db;
13 |
14 | public BaseRepository(DbContext db)
15 | {
16 | Db = db;
17 | }
18 |
19 | public virtual IQueryable Filter(
20 | Expression> filter = null,
21 | Func, IOrderedQueryable> orderBy = null,
22 | string includeProperties = "")
23 | {
24 | var query = Db.Set().AsQueryable();
25 | if (filter != null)
26 | {
27 | query = query.Where(filter);
28 | }
29 | if (!string.IsNullOrWhiteSpace(includeProperties))
30 | {
31 | var properties = includeProperties.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
32 | foreach (var includeProperty in properties)
33 | {
34 | query = query.Include(includeProperty);
35 | }
36 | }
37 | if (orderBy != null)
38 | {
39 | query = orderBy(query);
40 | }
41 | return query;
42 | }
43 |
44 | public IQueryable Get()
45 | {
46 | var query = Db.Set().AsQueryable();
47 | return query;
48 | }
49 | public TEntity GetById(string id)
50 | {
51 | return Db.Set().Find(id);
52 | }
53 |
54 | public virtual TEntity Add(TEntity entity)
55 | {
56 | return Db.Set().Add(entity);
57 | }
58 |
59 | public virtual IEnumerable Add(IEnumerable entities)
60 | {
61 | var range = Db.Set().AddRange(entities);
62 | return range;
63 | }
64 |
65 | public virtual bool Delete(TEntity entity)
66 | {
67 | var remove = Db.Set().Remove(entity);
68 | return true;
69 | }
70 |
71 | public virtual bool Edit(TEntity entity)
72 | {
73 | Db.Entry(entity).State = EntityState.Modified;
74 | return true;
75 | }
76 |
77 | public virtual bool Save()
78 | {
79 | var changes = Db.SaveChanges();
80 | return changes > 0;
81 | }
82 | }
83 | }
--------------------------------------------------------------------------------
/Commons/Commons/Repository/IGenericRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Linq.Expressions;
4 |
5 | namespace Commons.Repository
6 | {
7 | public interface IGenericRepository where T : class
8 | {
9 | T Add(T entity);
10 | bool Delete(T entity);
11 | bool Edit(T entity);
12 | bool Save();
13 |
14 | IQueryable Filter(
15 | Expression> filter = null,
16 | Func, IOrderedQueryable> orderBy = null,
17 | string includeProperties = "");
18 |
19 | IQueryable Get();
20 | }
21 | }
--------------------------------------------------------------------------------
/Commons/Commons/RequestModel/ExpressionHelper.cs:
--------------------------------------------------------------------------------
1 | namespace Commons.RequestModel
2 | {
3 | using System;
4 | using System.Linq;
5 | using System.Linq.Expressions;
6 |
7 | public static class ExpressionHelper
8 | {
9 | public static Expression Compose(this Expression first, Expression second,
10 | Func merge)
11 | {
12 | // build parameter map (from parameters of second to parameters of first)
13 | var map = first.Parameters.Select((f, i) => new { f, s = second.Parameters[i] })
14 | .ToDictionary(p => p.s, p => p.f);
15 |
16 | // replace parameters in the second lambda expression with parameters from the first
17 | var secondBody = ParameterRebinder.ReplaceParameters(map, second.Body);
18 |
19 | // apply composition of lambda expression bodies to parameters from the first expression
20 | return Expression.Lambda(merge(first.Body, secondBody), first.Parameters);
21 | }
22 |
23 | public static Expression> And(this Expression> first,
24 | Expression> second)
25 | {
26 | return first.Compose(second, Expression.And);
27 | }
28 |
29 | public static Expression> Or(this Expression> first,
30 | Expression> second)
31 | {
32 | return first.Compose(second, Expression.Or);
33 | }
34 |
35 | public static bool IdIsOk(this string id)
36 | {
37 | if (string.IsNullOrWhiteSpace(id))
38 | {
39 | return false;
40 | }
41 | Guid guid;
42 | if (!Guid.TryParse(id, out guid))
43 | {
44 | return false;
45 | }
46 | if (guid == new Guid())
47 | {
48 | return false;
49 | }
50 | return true;
51 | }
52 |
53 | }
54 | }
--------------------------------------------------------------------------------
/Commons/Commons/RequestModel/ParameterRebinder.cs:
--------------------------------------------------------------------------------
1 | namespace Commons.RequestModel
2 | {
3 | using System.Collections.Generic;
4 | using System.Linq.Expressions;
5 |
6 | public class ParameterRebinder : ExpressionVisitor
7 | {
8 | private readonly Dictionary map;
9 |
10 | public ParameterRebinder(Dictionary map)
11 | {
12 | this.map = map ?? new Dictionary();
13 | }
14 |
15 | public static Expression ReplaceParameters(Dictionary map,
16 | Expression exp)
17 | {
18 | return new ParameterRebinder(map).Visit(exp);
19 | }
20 |
21 | protected override Expression VisitParameter(ParameterExpression p)
22 | {
23 | ParameterExpression replacement;
24 | if (this.map.TryGetValue(p, out replacement))
25 | {
26 | p = replacement;
27 | }
28 | return base.VisitParameter(p);
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/Commons/Commons/RequestModel/ReplaceExpressionVisitor.cs:
--------------------------------------------------------------------------------
1 | namespace Commons.RequestModel
2 | {
3 | using System.Linq.Expressions;
4 |
5 | public class ReplaceExpressionVisitor
6 | : ExpressionVisitor
7 | {
8 | private readonly Expression _oldValue;
9 | private readonly Expression _newValue;
10 |
11 | public ReplaceExpressionVisitor(Expression oldValue, Expression newValue)
12 | {
13 | this._oldValue = oldValue;
14 | this._newValue = newValue;
15 | }
16 |
17 | public override Expression Visit(Expression node)
18 | {
19 | if (node == this._oldValue)
20 | return this._newValue;
21 | return base.Visit(node);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/Commons/Commons/RequestModel/RequestHelperModels.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 | using Commons.Model;
6 | using Commons.ViewModel;
7 |
8 | namespace Commons.RequestModel
9 | {
10 | public class OrderByRequest
11 | {
12 | public string PropertyName { get; set; }
13 | public bool IsAscending { get; set; }
14 | }
15 |
16 |
17 | public abstract class RequestModel where TModel : Entity
18 | {
19 | protected Expression> ExpressionObj = e => true;
20 |
21 | protected RequestModel(string keyword, string orderBy = "Modified", string isAscending = "False")
22 | {
23 | if (string.IsNullOrEmpty(keyword))
24 | {
25 | keyword = "";
26 | }
27 | Page = 1;
28 | Keyword = keyword.ToLower();
29 | if (!string.IsNullOrWhiteSpace(orderBy))
30 | {
31 | OrderBy = orderBy;
32 | }
33 | if (!string.IsNullOrWhiteSpace(isAscending))
34 | {
35 | IsAscending = isAscending;
36 | }
37 |
38 | Request = new OrderByRequest
39 | {
40 | PropertyName = string.IsNullOrWhiteSpace(OrderBy) ? "Modified" : OrderBy,
41 | IsAscending = IsAscending == "True"
42 | };
43 | }
44 |
45 | public string OrderBy { get; set; }
46 | public string IsAscending { get; set; }
47 | public DateTime StartDate { get; set; }
48 | public DateTime EndDate { get; set; }
49 | public int PerPageCount => 10;
50 | public int Page { get; set; }
51 | public List Tables { get; set; }
52 | public string Id { get; set; }
53 | public OrderByRequest Request { get; }
54 | public string Keyword { get; set; }
55 | public string ParentId { get; set; }
56 | public string ShopId { get; set; }
57 |
58 | protected Func, IOrderedQueryable> OrderByFunc()
59 | {
60 | string propertyName = Request.PropertyName;
61 | bool ascending = Request.IsAscending;
62 | var source = Expression.Parameter(typeof(IQueryable), "source");
63 | var item = Expression.Parameter(typeof(TSource), "item");
64 | var member = Expression.Property(item, propertyName);
65 | var selector = Expression.Quote(Expression.Lambda(member, item));
66 | var body = Expression.Call(
67 | typeof(Queryable), @ascending ? "OrderBy" : "OrderByDescending",
68 | new[] { item.Type, member.Type },
69 | source, selector);
70 | var expr = Expression.Lambda, IOrderedQueryable>>(body, source);
71 | var func = expr.Compile();
72 | return func;
73 | }
74 |
75 | protected abstract Expression> GetExpression();
76 | public virtual IQueryable IncludeParents(IQueryable queryable)
77 | {
78 | return queryable;
79 | }
80 |
81 | public abstract Expression> Dropdown();
82 |
83 | public IQueryable GetOrderedData(IQueryable queryable)
84 | {
85 | queryable = queryable.Where(GetExpression());
86 | queryable = OrderByFunc()(queryable);
87 | return queryable;
88 | }
89 |
90 | public IQueryable SkipAndTake(IQueryable queryable)
91 | {
92 | if (Page != -1)
93 | {
94 | queryable = queryable.Skip((Page - 1) * PerPageCount).Take(PerPageCount);
95 | }
96 |
97 | return queryable;
98 | }
99 |
100 | public IQueryable GetData(IQueryable queryable)
101 | {
102 | return queryable.Where(GetExpression());
103 | }
104 |
105 | public TModel GetFirstData(IQueryable queryable)
106 | {
107 | return queryable.First(GetExpression());
108 | }
109 |
110 | protected Expression> GenerateBaseEntityExpression()
111 | {
112 | if (Id.IdIsOk())
113 | {
114 | ExpressionObj = ExpressionObj.And(x => x.Id == Id);
115 | }
116 |
117 | if (StartDate != new DateTime())
118 | {
119 | StartDate = StartDate.Date;
120 | if (EndDate != new DateTime())
121 | {
122 | EndDate = EndDate.Date.AddDays(1).AddMinutes(-1);
123 | }
124 | else
125 | {
126 | EndDate = DateTime.Today.Date.AddDays(1).AddMinutes(-1);
127 | }
128 | ExpressionObj = ExpressionObj.And(x => x.Modified >= StartDate && x.Modified <= EndDate);
129 | }
130 |
131 | return ExpressionObj;
132 | }
133 | }
134 | }
--------------------------------------------------------------------------------
/Commons/Commons/Service/BaseService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data.Entity;
4 | using System.Linq;
5 | using System.Linq.Expressions;
6 | using System.Threading.Tasks;
7 | using Commons.Model;
8 | using Commons.Repository;
9 | using Commons.RequestModel;
10 | using Commons.ViewModel;
11 |
12 | namespace Commons.Service
13 | {
14 | public class BaseService : IBaseService where T : Entity where TRm : RequestModel where TVm : BaseViewModel
15 | {
16 | protected BaseRepository Repository;
17 |
18 | public BaseService(BaseRepository repository)
19 | {
20 | Repository = repository;
21 | }
22 |
23 | public virtual bool Add(T entity)
24 | {
25 | var add = Repository.Add(entity);
26 | var save = Repository.Save();
27 | return save;
28 | }
29 |
30 |
31 | public bool Delete(T entity)
32 | {
33 | bool deleted = Repository.Delete(entity);
34 | Repository.Save();
35 | return deleted;
36 | }
37 |
38 | public bool Delete(string id)
39 | {
40 | var entity = Repository.Filter(x => x.Id == id).FirstOrDefault();
41 | bool deleted = Repository.Delete(entity);
42 | Repository.Save();
43 | return deleted;
44 | }
45 |
46 | public virtual bool Edit(T entity)
47 | {
48 | bool edit = Repository.Edit(entity);
49 | Repository.Save();
50 | return edit;
51 | }
52 |
53 | public T GetById(string id)
54 | {
55 | return Repository.GetById(id);
56 | }
57 |
58 | public async Task> GetAllAsync()
59 | {
60 | var queryable = await Repository.Get().ToListAsync();
61 | var vms = queryable.Select(x => (TVm) Activator.CreateInstance(typeof(TVm), new object[] {x}));
62 | return vms.ToList();
63 | }
64 |
65 | public List GetDropdownListAsync(TRm request)
66 | {
67 | IQueryable queryable = Repository.Get();
68 | queryable = request.GetOrderedData(queryable);
69 | List list = queryable.Select(request.Dropdown()).ToList();
70 | return list;
71 | }
72 |
73 | public async Task,int>> SearchAsync(TRm request)
74 | {
75 | var queryable = request.GetOrderedData(Repository.Get());
76 | int count = queryable.Count();
77 | queryable = request.SkipAndTake(queryable);
78 | queryable = request.IncludeParents(queryable);
79 | var list = await queryable.ToListAsync();
80 | List vms = list.ConvertAll(CreateVmInstance);
81 | return new Tuple, int>(vms,count);
82 | }
83 |
84 | private static TVm CreateVmInstance(T x)
85 | {
86 | return (TVm)Activator.CreateInstance(typeof(TVm), x);
87 | }
88 |
89 | public TVm GetDetail(string id)
90 | {
91 | var model = Repository.GetById(id);
92 | if (model == null)
93 | {
94 | return null;
95 | }
96 | return CreateVmInstance(model);
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/Commons/Commons/Service/IBaseService.cs:
--------------------------------------------------------------------------------
1 | using Commons.Model;
2 |
3 | namespace Commons.Service
4 | {
5 | public interface IBaseService where T : Entity
6 | {
7 | bool Add(T entity);
8 | bool Delete(T entity);
9 | bool Delete(string id);
10 | bool Edit(T entity);
11 | }
12 | }
--------------------------------------------------------------------------------
/Commons/Commons/Utility/ExtensionMethods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Dynamic;
4 | using System.Linq;
5 | using System.Reflection;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Commons.ViewModel;
9 | using Newtonsoft.Json;
10 |
11 | namespace Commons.Utility
12 | {
13 | public static class ExtensionMethods
14 | {
15 | public static object GetValue(this object obj, List propertyInfos)
16 | {
17 | Dictionary dictionary = new Dictionary();
18 | foreach (var p in propertyInfos)
19 | {
20 | var value = p.GetValue(obj);
21 | dictionary.Add(p.Name, value);
22 | }
23 | var expandoObject = new ExpandoObject();
24 | var keyValuePairs = (ICollection>)expandoObject;
25 | foreach (var kvp in dictionary)
26 | {
27 | keyValuePairs.Add(kvp);
28 | }
29 | return expandoObject;
30 | }
31 |
32 | // don't know why but this function doesn't get called when we put it in here
33 | //public static List ConvertToViewableDynamicList(this List