├── .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 models) 34 | //{ 35 | // Type modelType = models.First().GetType(); 36 | // //you should send the IsViewable type as parameter. I didn't do this because i don't need to 37 | // Type viewable = typeof(IsViewable); 38 | // List propertyInfos = modelType.GetProperties().Where(x => x.CustomAttributes.Any(y => y.AttributeType == viewable)).ToList(); 39 | // List list = models.Select(x => x.GetValue(propertyInfos)).ToList(); 40 | // List deserializeObject = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(list)); 41 | // return deserializeObject; 42 | //} 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Commons/Commons/ViewModel/BaseViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Commons.Model; 3 | 4 | namespace Commons.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 | [IsViewable(Value = true)] 18 | public string Id { get; set; } 19 | 20 | public DateTime Created { get; set; } 21 | 22 | public string CreatedBy { get; set; } 23 | 24 | public DateTime Modified { get; set; } 25 | 26 | public string ModifiedBy { get; set; } 27 | } 28 | } -------------------------------------------------------------------------------- /Commons/Commons/ViewModel/DropdownViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace Commons.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 | } -------------------------------------------------------------------------------- /Commons/Commons/ViewModel/IsViewable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Commons.ViewModel 4 | { 5 | [AttributeUsage(AttributeTargets.Property)] 6 | public class IsViewable: Attribute 7 | { 8 | public bool Value { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /Commons/Commons/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/ApplicationLibrary.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {EB368842-53B0-4F00-B7A0-39D921FF9393} 8 | Library 9 | Properties 10 | ApplicationLibrary 11 | ApplicationLibrary 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.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 | 201612030350205_StudentDepartment.cs 56 | 57 | 58 | 59 | 201612040332398_dontknowwhatischagned.cs 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {482131e7-7567-4540-bc11-7125957e7ff5} 77 | Commons 78 | 79 | 80 | 81 | 82 | 201612030350205_StudentDepartment.cs 83 | 84 | 85 | 201612040332398_dontknowwhatischagned.cs 86 | 87 | 88 | 89 | 90 | 97 | -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/BusinessDbContext.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Entity; 2 | using ApplicationLibrary.Models.Departments; 3 | using ApplicationLibrary.Models.Students; 4 | 5 | namespace ApplicationLibrary 6 | { 7 | public class BusinessDbContext : DbContext 8 | { 9 | public BusinessDbContext() : base("DefaultConnection") 10 | { 11 | 12 | } 13 | public DbSet Students { get; set; } 14 | 15 | public DbSet Departments { get; set; } 16 | 17 | 18 | private static BusinessDbContext _db; 19 | public static BusinessDbContext CreateInstance() 20 | { 21 | return _db ?? (_db = new BusinessDbContext()); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/Migrations/201612030350205_StudentDepartment.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | namespace ApplicationLibrary.Migrations 3 | { 4 | using System.CodeDom.Compiler; 5 | using System.Data.Entity.Migrations; 6 | using System.Data.Entity.Migrations.Infrastructure; 7 | using System.Resources; 8 | 9 | [GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")] 10 | public sealed partial class StudentDepartment : IMigrationMetadata 11 | { 12 | private readonly ResourceManager Resources = new ResourceManager(typeof(StudentDepartment)); 13 | 14 | string IMigrationMetadata.Id 15 | { 16 | get { return "201612030350205_StudentDepartment"; } 17 | } 18 | 19 | string IMigrationMetadata.Source 20 | { 21 | get { return null; } 22 | } 23 | 24 | string IMigrationMetadata.Target 25 | { 26 | get { return Resources.GetString("Target"); } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/Migrations/201612030350205_StudentDepartment.cs: -------------------------------------------------------------------------------- 1 | namespace ApplicationLibrary.Migrations 2 | { 3 | using System; 4 | using System.Data.Entity.Migrations; 5 | 6 | public partial class StudentDepartment : DbMigration 7 | { 8 | public override void Up() 9 | { 10 | CreateTable( 11 | "dbo.Departments", 12 | c => new 13 | { 14 | Id = c.String(nullable: false, maxLength: 128), 15 | Name = c.String(nullable: false, maxLength: 128), 16 | Created = c.DateTime(nullable: false), 17 | CreatedBy = c.String(nullable: false), 18 | Modified = c.DateTime(nullable: false), 19 | ModifiedBy = c.String(nullable: false), 20 | }) 21 | .PrimaryKey(t => t.Id) 22 | .Index(t => t.Name); 23 | 24 | CreateTable( 25 | "dbo.Students", 26 | c => new 27 | { 28 | Id = c.String(nullable: false, maxLength: 128), 29 | Name = c.String(nullable: false, maxLength: 128), 30 | Phone = c.String(), 31 | DepartmentId = c.String(maxLength: 128), 32 | Created = c.DateTime(nullable: false), 33 | CreatedBy = c.String(nullable: false), 34 | Modified = c.DateTime(nullable: false), 35 | ModifiedBy = c.String(nullable: false), 36 | }) 37 | .PrimaryKey(t => t.Id) 38 | .ForeignKey("dbo.Departments", t => t.DepartmentId) 39 | .Index(t => t.Name) 40 | .Index(t => t.DepartmentId); 41 | 42 | } 43 | 44 | public override void Down() 45 | { 46 | DropForeignKey("dbo.Students", "DepartmentId", "dbo.Departments"); 47 | DropIndex("dbo.Students", new[] { "DepartmentId" }); 48 | DropIndex("dbo.Students", new[] { "Name" }); 49 | DropIndex("dbo.Departments", new[] { "Name" }); 50 | DropTable("dbo.Students"); 51 | DropTable("dbo.Departments"); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/Migrations/201612040332398_dontknowwhatischagned.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | namespace ApplicationLibrary.Migrations 3 | { 4 | using System.CodeDom.Compiler; 5 | using System.Data.Entity.Migrations; 6 | using System.Data.Entity.Migrations.Infrastructure; 7 | using System.Resources; 8 | 9 | [GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")] 10 | public sealed partial class dontknowwhatischagned : IMigrationMetadata 11 | { 12 | private readonly ResourceManager Resources = new ResourceManager(typeof(dontknowwhatischagned)); 13 | 14 | string IMigrationMetadata.Id 15 | { 16 | get { return "201612040332398_dontknowwhatischagned"; } 17 | } 18 | 19 | string IMigrationMetadata.Source 20 | { 21 | get { return null; } 22 | } 23 | 24 | string IMigrationMetadata.Target 25 | { 26 | get { return Resources.GetString("Target"); } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/Migrations/201612040332398_dontknowwhatischagned.cs: -------------------------------------------------------------------------------- 1 | namespace ApplicationLibrary.Migrations 2 | { 3 | using System; 4 | using System.Data.Entity.Migrations; 5 | 6 | public partial class dontknowwhatischagned : DbMigration 7 | { 8 | public override void Up() 9 | { 10 | DropForeignKey("dbo.Students", "DepartmentId", "dbo.Departments"); 11 | DropIndex("dbo.Students", new[] { "DepartmentId" }); 12 | AlterColumn("dbo.Students", "DepartmentId", c => c.String(nullable: false, maxLength: 128)); 13 | CreateIndex("dbo.Students", "DepartmentId"); 14 | AddForeignKey("dbo.Students", "DepartmentId", "dbo.Departments", "Id", cascadeDelete: false); 15 | } 16 | 17 | public override void Down() 18 | { 19 | DropForeignKey("dbo.Students", "DepartmentId", "dbo.Departments"); 20 | DropIndex("dbo.Students", new[] { "DepartmentId" }); 21 | AlterColumn("dbo.Students", "DepartmentId", c => c.String(maxLength: 128)); 22 | CreateIndex("dbo.Students", "DepartmentId"); 23 | AddForeignKey("dbo.Students", "DepartmentId", "dbo.Departments", "Id"); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/Migrations/Configuration.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Entity.Migrations; 2 | 3 | namespace ApplicationLibrary.Migrations 4 | { 5 | internal sealed class Configuration : DbMigrationsConfiguration 6 | { 7 | public Configuration() 8 | { 9 | AutomaticMigrationsEnabled = false; 10 | } 11 | 12 | protected override void Seed(BusinessDbContext context) 13 | { 14 | // This method will be called after migrating to the latest version. 15 | 16 | // You can use the DbSet.AddOrUpdate() helper extension method 17 | // to avoid creating duplicate seed data. E.g. 18 | // 19 | // context.People.AddOrUpdate( 20 | // p => p.FullName, 21 | // new Person { FullName = "Andrew Peters" }, 22 | // new Person { FullName = "Brice Lambson" }, 23 | // new Person { FullName = "Rowan Miller" } 24 | // ); 25 | // 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/Models/Departments/Department.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using ApplicationLibrary.Models.Students; 6 | using Commons.Model; 7 | 8 | namespace ApplicationLibrary.Models.Departments 9 | { 10 | public class Department : Entity 11 | { 12 | [Required] 13 | [Index] 14 | [StringLength(128)] 15 | public string Name { get; set; } 16 | 17 | public virtual ICollection Students { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/Models/Departments/DepartmentRequestModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Linq.Expressions; 4 | using Commons.RequestModel; 5 | using Commons.ViewModel; 6 | 7 | namespace ApplicationLibrary.Models.Departments 8 | { 9 | public class DepartmentRequestModel : RequestModel 10 | { 11 | public DepartmentRequestModel(string keyword="", string orderBy = "Modified", string isAscending="false") : base(keyword, orderBy, isAscending) 12 | { 13 | } 14 | 15 | protected override Expression> GetExpression() 16 | { 17 | // by which property we want to query on this table? 18 | if (!string.IsNullOrWhiteSpace(Keyword)) 19 | { 20 | ExpressionObj = x => x.Name.ToLower().Contains(Keyword); 21 | } 22 | ExpressionObj = ExpressionObj.And(GenerateBaseEntityExpression()); 23 | return ExpressionObj; 24 | } 25 | 26 | public override IQueryable IncludeParents(IQueryable queryable) 27 | { 28 | return queryable; 29 | } 30 | 31 | public override Expression> Dropdown() 32 | { 33 | return x => new DropdownViewModel() 34 | { 35 | Id = x.Id, 36 | Text = x.Name 37 | }; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/Models/Departments/DepartmetnViewModel.cs: -------------------------------------------------------------------------------- 1 | using Commons.ViewModel; 2 | 3 | namespace ApplicationLibrary.Models.Departments 4 | { 5 | public class DepartmetnViewModel : BaseViewModel 6 | { 7 | public DepartmetnViewModel(Department x) : base(x) 8 | { 9 | Name = x.Name; 10 | } 11 | 12 | [IsViewable(Value = true)] 13 | public string Name { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/Models/Students/Student.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | using ApplicationLibrary.Models.Departments; 4 | using Commons.Model; 5 | 6 | namespace ApplicationLibrary.Models.Students 7 | { 8 | public class Student : Entity 9 | { 10 | [Required] 11 | [Index] 12 | [StringLength(128)] 13 | public string Name { get; set; } 14 | public string Phone { get; set; } 15 | 16 | [Required] 17 | public string DepartmentId { get; set; } 18 | [ForeignKey("DepartmentId")] 19 | public virtual Department Department { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/Models/Students/StudentRequestModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.Entity; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using Commons.RequestModel; 6 | using Commons.ViewModel; 7 | 8 | namespace ApplicationLibrary.Models.Students 9 | { 10 | public class StudentRequestModel : RequestModel 11 | { 12 | public StudentRequestModel(string keyword="", string orderBy="Modified", string isAscending="false") : base(keyword, orderBy, isAscending) 13 | { 14 | } 15 | 16 | protected override Expression> GetExpression() 17 | { 18 | if (!string.IsNullOrWhiteSpace(Keyword)) 19 | { 20 | ExpressionObj = x => x.Name.ToLower().Contains(Keyword) || x.Phone.ToLower().Contains(Keyword); 21 | } 22 | if (ParentId.IdIsOk()) 23 | { 24 | ExpressionObj = ExpressionObj.And(x => x.DepartmentId == ParentId); 25 | } 26 | ExpressionObj = ExpressionObj.And(GenerateBaseEntityExpression()); 27 | return ExpressionObj; 28 | } 29 | 30 | public override Expression> Dropdown() 31 | { 32 | return x => new DropdownViewModel() 33 | { 34 | Id = x.Id, 35 | Text = x.Name 36 | }; 37 | } 38 | 39 | public override IQueryable IncludeParents(IQueryable students) 40 | { 41 | return students.Include(x => x.Department).AsQueryable(); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/Models/Students/StudentViewModel.cs: -------------------------------------------------------------------------------- 1 | using ApplicationLibrary.Models.Departments; 2 | using Commons.ViewModel; 3 | 4 | namespace ApplicationLibrary.Models.Students 5 | { 6 | public class StudentViewModel : BaseViewModel 7 | { 8 | public StudentViewModel(Student x) : base(x) 9 | { 10 | Name = x.Name; 11 | Phone = x.Phone; 12 | if (x.Department!=null) 13 | { 14 | Department = new DepartmetnViewModel(x.Department); 15 | DepartmentName = this.Department.Name; 16 | } 17 | } 18 | 19 | [IsViewable(Value = true)] 20 | public string Phone { get; set; } 21 | 22 | [IsViewable(Value = true)] 23 | public string Name { get; set; } 24 | 25 | [IsViewable(Value = true)] 26 | public string DepartmentName { get; set; } 27 | 28 | public DepartmetnViewModel Department { get; set; } 29 | } 30 | } -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/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("ApplicationLibrary")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ApplicationLibrary")] 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("eb368842-53b0-4f00-b7a0-39d921ff9393")] 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 | -------------------------------------------------------------------------------- /ConsumerApps/ApplicationLibrary/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerApps.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}") = "ConsumerConsoleApp", "ConsumerConsoleApp\ConsumerConsoleApp.csproj", "{BD0B7147-A4D4-46D8-AE35-1EA65B6F34F4}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commons", "..\Commons\Commons\Commons.csproj", "{482131E7-7567-4540-BC11-7125957E7FF5}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApplicationLibrary", "ApplicationLibrary\ApplicationLibrary.csproj", "{EB368842-53B0-4F00-B7A0-39D921FF9393}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsumerWinFormsApp", "ConsumerWinFormsApp\ConsumerWinFormsApp.csproj", "{4B49F57A-59D3-43C2-AB71-3F5C2F0E4112}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsumerWpfApp", "ConsumerWpfApp\ConsumerWpfApp.csproj", "{031A091B-5E0A-44AB-83DC-6202BF007E8E}" 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 | {BD0B7147-A4D4-46D8-AE35-1EA65B6F34F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {BD0B7147-A4D4-46D8-AE35-1EA65B6F34F4}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {BD0B7147-A4D4-46D8-AE35-1EA65B6F34F4}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {BD0B7147-A4D4-46D8-AE35-1EA65B6F34F4}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {482131E7-7567-4540-BC11-7125957E7FF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {482131E7-7567-4540-BC11-7125957E7FF5}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {482131E7-7567-4540-BC11-7125957E7FF5}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {482131E7-7567-4540-BC11-7125957E7FF5}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {EB368842-53B0-4F00-B7A0-39D921FF9393}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {EB368842-53B0-4F00-B7A0-39D921FF9393}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {EB368842-53B0-4F00-B7A0-39D921FF9393}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {EB368842-53B0-4F00-B7A0-39D921FF9393}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {4B49F57A-59D3-43C2-AB71-3F5C2F0E4112}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {4B49F57A-59D3-43C2-AB71-3F5C2F0E4112}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {4B49F57A-59D3-43C2-AB71-3F5C2F0E4112}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {4B49F57A-59D3-43C2-AB71-3F5C2F0E4112}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {031A091B-5E0A-44AB-83DC-6202BF007E8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {031A091B-5E0A-44AB-83DC-6202BF007E8E}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {031A091B-5E0A-44AB-83DC-6202BF007E8E}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {031A091B-5E0A-44AB-83DC-6202BF007E8E}.Release|Any CPU.Build.0 = Release|Any CPU 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | EndGlobal 47 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerConsoleApp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerConsoleApp/ConsumerConsoleApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {BD0B7147-A4D4-46D8-AE35-1EA65B6F34F4} 8 | Exe 9 | Properties 10 | ConsumerConsoleApp 11 | ConsumerConsoleApp 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll 37 | True 38 | 39 | 40 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll 41 | True 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 | {482131E7-7567-4540-BC11-7125957E7FF5} 67 | Commons 68 | 69 | 70 | {EB368842-53B0-4F00-B7A0-39D921FF9393} 71 | ApplicationLibrary 72 | 73 | 74 | 75 | 82 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerConsoleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApplicationLibrary; 7 | using ApplicationLibrary.Models.Departments; 8 | using Commons.Repository; 9 | using Commons.RequestModel; 10 | using Commons.Service; 11 | 12 | namespace ConsumerConsoleApp 13 | { 14 | class Program 15 | { 16 | static void Main(string[] args) 17 | { 18 | var db = new BusinessDbContext(); 19 | var departmentRepo = new BaseRepository(db); 20 | var departmentService = new BaseService(departmentRepo); 21 | 22 | // we set the fake values here 23 | var department = new Department() 24 | { 25 | Id = Guid.NewGuid().ToString(), 26 | Name = "department-" + DateTime.Now.Ticks, 27 | Created = DateTime.Now, 28 | Modified = DateTime.Now, 29 | CreatedBy = "foyzulkarim@gmail.com", 30 | ModifiedBy = "foyzulkarim@gmail.com" 31 | }; 32 | departmentService.Add(department); 33 | 34 | //now lets fetch those all 35 | //var departments = departmentService.GetAllAsync().GetAwaiter().GetResult(); 36 | //foreach (var d in departments) 37 | //{ 38 | // Console.WriteLine(d.Name); 39 | //} 40 | 41 | // now lets search by keyword 42 | Console.WriteLine("Input your keyword and press Enter: "); 43 | var keyword = Console.ReadLine(); 44 | 45 | DepartmentRequestModel request=new DepartmentRequestModel(keyword); 46 | var result = departmentService.SearchAsync(request).GetAwaiter().GetResult(); 47 | Console.WriteLine("Search result : "+result.Item2); 48 | foreach (var viewModel in result.Item1) 49 | { 50 | Console.WriteLine(viewModel.Name); 51 | } 52 | Console.Read(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerConsoleApp/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("ConsumerConsoleApp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ConsumerConsoleApp")] 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("bd0b7147-a4d4-46d8-ae35-1ea65b6f34f4")] 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 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerConsoleApp/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/App.cs: -------------------------------------------------------------------------------- 1 | using ApplicationLibrary; 2 | using ApplicationLibrary.Models.Departments; 3 | using ApplicationLibrary.Models.Students; 4 | using Commons.Model; 5 | using Commons.Repository; 6 | using Commons.Service; 7 | 8 | namespace ConsumerWinFormsApp 9 | { 10 | public static class App 11 | { 12 | static App() 13 | { 14 | StudentService = new BaseService(CreateRepository()); 15 | DepartmentService = new BaseService(CreateRepository()); 16 | } 17 | 18 | public static BaseRepository CreateRepository() where T : Entity 19 | { 20 | return new BaseRepository(BusinessDbContext.CreateInstance()); 21 | } 22 | 23 | public static BaseService StudentService { get; set; } 24 | public static BaseService DepartmentService { get; set; } 25 | } 26 | } -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Commons.Model; 3 | using Commons.Repository; 4 | 5 | namespace ConsumerWinFormsApp 6 | { 7 | public static class Constants 8 | { 9 | public static string UserName { get; set; } 10 | 11 | public static Entity SetCommonValues(this Entity entity) 12 | { 13 | entity.Id = Guid.NewGuid().ToString(); 14 | entity.Created = DateTime.Now; 15 | entity.Modified = DateTime.Now; 16 | entity.CreatedBy = Constants.UserName; 17 | entity.ModifiedBy = Constants.UserName; 18 | return entity; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/DepartmentForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | using ApplicationLibrary.Models.Departments; 11 | using ApplicationLibrary.Models.Students; 12 | using Commons.Utility; 13 | using Commons.ViewModel; 14 | 15 | namespace ConsumerWinFormsApp 16 | { 17 | public partial class DepartmentForm : Form, IGenericForm 18 | { 19 | DepartmentRequestModel requestModel; 20 | 21 | public DepartmentForm() 22 | { 23 | InitializeComponent(); 24 | Load += Form_Load; 25 | saveButton.Click += saveButton_Click; 26 | searchButton.Click += searchButton_Click; 27 | } 28 | 29 | private void Form_Load(object sender, EventArgs e) 30 | { 31 | requestModel = new DepartmentRequestModel(""); 32 | searchTextBox.DataBindings.Add("Text", requestModel, "Keyword"); 33 | } 34 | 35 | private void saveButton_Click(object sender, EventArgs e) 36 | { 37 | try 38 | { 39 | var m = CreateModel(); 40 | App.DepartmentService.Add(m); 41 | MessageBox.Show("Saved"); 42 | ClearForm(); 43 | } 44 | catch (Exception exception) 45 | { 46 | MessageBox.Show("Error Occurred"); 47 | } 48 | } 49 | 50 | private void searchButton_Click(object sender, EventArgs e) 51 | { 52 | LoadGridView(); 53 | } 54 | 55 | private void modelListTabPage_Enter(object sender, EventArgs e) 56 | { 57 | LoadGridView(); 58 | } 59 | 60 | public Department CreateModel() 61 | { 62 | Department model = new Department() 63 | { 64 | Name = nameTextBox.Text 65 | }; 66 | model.SetCommonValues(); 67 | return model; 68 | } 69 | 70 | public void ClearForm() 71 | { 72 | nameTextBox.Clear(); 73 | } 74 | 75 | public async Task LoadGridView() 76 | { 77 | Tuple, int> result = await App.DepartmentService.SearchAsync(requestModel); 78 | dataGridView1.DataSource = null; 79 | dataGridView1.DataSource = result.Item1.OfType().ToList().ConvertToViewableDynamicList(); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/ExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Commons.Utility; 8 | using Commons.ViewModel; 9 | using Newtonsoft.Json; 10 | 11 | namespace ConsumerWinFormsApp 12 | { 13 | public static class ExtensionMethods 14 | { 15 | public static List ConvertToViewableDynamicList(this List models) 16 | { 17 | Type modelType = models.First().GetType(); 18 | //you should send the IsViewable type as parameter. I didn't do this because i don't need to 19 | Type viewable = typeof(IsViewable); 20 | List propertyInfos = modelType.GetProperties().Where(x => x.CustomAttributes.Any(y => y.AttributeType == viewable)).ToList(); 21 | List list = models.Select(x => x.GetValue(propertyInfos)).ToList(); 22 | List deserializeObject = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(list)); 23 | return deserializeObject; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace ConsumerWinFormsApp 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.studentsButton = new System.Windows.Forms.Button(); 32 | this.departmentsButton = new System.Windows.Forms.Button(); 33 | this.button3 = new System.Windows.Forms.Button(); 34 | this.closeButton = new System.Windows.Forms.Button(); 35 | this.SuspendLayout(); 36 | // 37 | // studentsButton 38 | // 39 | this.studentsButton.Location = new System.Drawing.Point(28, 25); 40 | this.studentsButton.Name = "studentsButton"; 41 | this.studentsButton.Size = new System.Drawing.Size(168, 73); 42 | this.studentsButton.TabIndex = 0; 43 | this.studentsButton.Text = "Students"; 44 | this.studentsButton.UseVisualStyleBackColor = true; 45 | this.studentsButton.Click += new System.EventHandler(this.studentsButton_Click); 46 | // 47 | // departmentsButton 48 | // 49 | this.departmentsButton.Location = new System.Drawing.Point(235, 25); 50 | this.departmentsButton.Name = "departmentsButton"; 51 | this.departmentsButton.Size = new System.Drawing.Size(168, 73); 52 | this.departmentsButton.TabIndex = 1; 53 | this.departmentsButton.Text = "Departments"; 54 | this.departmentsButton.UseVisualStyleBackColor = true; 55 | this.departmentsButton.Click += new System.EventHandler(this.departmentsButton_Click); 56 | // 57 | // button3 58 | // 59 | this.button3.Location = new System.Drawing.Point(443, 25); 60 | this.button3.Name = "button3"; 61 | this.button3.Size = new System.Drawing.Size(168, 73); 62 | this.button3.TabIndex = 2; 63 | this.button3.Text = "Course"; 64 | this.button3.UseVisualStyleBackColor = true; 65 | // 66 | // closeButton 67 | // 68 | this.closeButton.Location = new System.Drawing.Point(136, 422); 69 | this.closeButton.Name = "closeButton"; 70 | this.closeButton.Size = new System.Drawing.Size(386, 78); 71 | this.closeButton.TabIndex = 3; 72 | this.closeButton.Text = "Close"; 73 | this.closeButton.UseVisualStyleBackColor = true; 74 | this.closeButton.Click += new System.EventHandler(this.closeButton_Click); 75 | // 76 | // Form1 77 | // 78 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 79 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 80 | this.ClientSize = new System.Drawing.Size(623, 512); 81 | this.Controls.Add(this.closeButton); 82 | this.Controls.Add(this.button3); 83 | this.Controls.Add(this.departmentsButton); 84 | this.Controls.Add(this.studentsButton); 85 | this.Name = "Form1"; 86 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 87 | this.Text = "Form1"; 88 | this.ResumeLayout(false); 89 | 90 | } 91 | 92 | #endregion 93 | 94 | private System.Windows.Forms.Button studentsButton; 95 | private System.Windows.Forms.Button departmentsButton; 96 | private System.Windows.Forms.Button button3; 97 | private System.Windows.Forms.Button closeButton; 98 | } 99 | } 100 | 101 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Reflection; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows.Forms; 11 | using ApplicationLibrary.Models.Students; 12 | 13 | namespace ConsumerWinFormsApp 14 | { 15 | public partial class Form1 : Form 16 | { 17 | public Form1() 18 | { 19 | InitializeComponent(); 20 | } 21 | 22 | private void studentsButton_Click(object sender, EventArgs e) 23 | { 24 | StudentsForm form = new StudentsForm(); 25 | form.ShowDialog(this); 26 | } 27 | 28 | 29 | 30 | private void closeButton_Click(object sender, EventArgs e) 31 | { 32 | this.Close(); 33 | } 34 | 35 | private void departmentsButton_Click(object sender, EventArgs e) 36 | { 37 | DepartmentForm form = new DepartmentForm(); 38 | form.ShowDialog(this); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/IGenericForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using System.Windows.Forms; 4 | using Commons.Model; 5 | using Commons.RequestModel; 6 | using Commons.Service; 7 | using Commons.ViewModel; 8 | 9 | namespace ConsumerWinFormsApp 10 | { 11 | public interface IGenericForm where T : Entity 12 | { 13 | T CreateModel(); 14 | void ClearForm(); 15 | Task LoadGridView(); 16 | } 17 | } -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace ConsumerWinFormsApp 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Constants.UserName = "foyzulkarim@gmail.com"; 20 | Application.Run(new Form1()); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/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("ConsumerWinFormsApp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ConsumerWinFormsApp")] 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("4b49f57a-59d3-43c2-ab71-3f5c2f0e4112")] 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 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ConsumerWinFormsApp.Properties 12 | { 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ConsumerWinFormsApp.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ConsumerWinFormsApp.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/SampleForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace ConsumerWinFormsApp 2 | { 3 | partial class SampleForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.userControl11 = new ConsumerWinFormsApp.UserControls.UserControl1(); 32 | this.SuspendLayout(); 33 | // 34 | // userControl11 35 | // 36 | this.userControl11.Dock = System.Windows.Forms.DockStyle.Fill; 37 | this.userControl11.Location = new System.Drawing.Point(0, 0); 38 | this.userControl11.Name = "userControl11"; 39 | this.userControl11.Size = new System.Drawing.Size(1164, 662); 40 | this.userControl11.TabIndex = 0; 41 | // 42 | // SampleForm 43 | // 44 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 45 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 46 | this.ClientSize = new System.Drawing.Size(1164, 662); 47 | this.Controls.Add(this.userControl11); 48 | this.Name = "SampleForm"; 49 | this.Text = "SampleForm"; 50 | this.ResumeLayout(false); 51 | 52 | } 53 | 54 | #endregion 55 | 56 | private UserControls.UserControl1 userControl11; 57 | } 58 | } -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/SampleForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace ConsumerWinFormsApp 12 | { 13 | public partial class SampleForm : Form 14 | { 15 | public SampleForm() 16 | { 17 | InitializeComponent(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/SampleForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/StudentsForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Dynamic; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Threading.Tasks; 8 | using System.Windows.Forms; 9 | using ApplicationLibrary.Models.Departments; 10 | using ApplicationLibrary.Models.Students; 11 | using Commons.Model; 12 | using Commons.Service; 13 | using Commons.Utility; 14 | using Commons.ViewModel; 15 | using Newtonsoft.Json; 16 | 17 | namespace ConsumerWinFormsApp 18 | { 19 | public partial class StudentsForm : Form, IGenericForm 20 | { 21 | StudentRequestModel studentRequestModel; 22 | 23 | public StudentsForm() 24 | { 25 | InitializeComponent(); 26 | 27 | Load += Form_Load; 28 | saveButton.Click += saveButton_Click; 29 | searchButton.Click += searchButton_Click; 30 | 31 | } 32 | 33 | private void Form_Load(object sender, EventArgs e) 34 | { 35 | studentRequestModel = new StudentRequestModel(""); 36 | searchTextBox.DataBindings.Add("Text", studentRequestModel, "Keyword"); 37 | List departments = App.DepartmentService.GetDropdownListAsync(new DepartmentRequestModel()); 38 | LoadDropdown(departments); 39 | } 40 | 41 | private void saveButton_Click(object sender, EventArgs e) 42 | { 43 | try 44 | { 45 | var m = CreateModel(); 46 | App.StudentService.Add(m); 47 | MessageBox.Show("Saved"); 48 | ClearForm(); 49 | } 50 | catch (Exception exception) 51 | { 52 | MessageBox.Show("Error Occurred"); 53 | } 54 | } 55 | 56 | private void searchButton_Click(object sender, EventArgs e) 57 | { 58 | LoadGridView(); 59 | } 60 | 61 | private void modelListTabPage_Enter(object sender, EventArgs e) 62 | { 63 | LoadGridView(); 64 | } 65 | 66 | private void LoadDropdown(List departments) 67 | { 68 | departmentComboBox.DataSource = departments; 69 | departmentComboBox.DisplayMember = "Text"; 70 | departmentComboBox.ValueMember = "Id"; 71 | } 72 | 73 | private void clearButton_Click(object sender, EventArgs e) 74 | { 75 | ClearForm(); 76 | } 77 | 78 | public void ClearForm() 79 | { 80 | nameTextBox.Clear(); 81 | phoneTextBox.Clear(); 82 | } 83 | 84 | public async Task LoadGridView() 85 | { 86 | var result = await App.StudentService.SearchAsync(studentRequestModel); 87 | dataGridView1.DataSource = null; 88 | List objects = result.Item1.OfType().ToList(); 89 | dataGridView1.DataSource = objects.ConvertToViewableDynamicList(); 90 | } 91 | 92 | public void LoadDropdown() 93 | { 94 | departmentComboBox.DataSource = App.DepartmentService.GetDropdownListAsync(new DepartmentRequestModel()); 95 | } 96 | 97 | public Student CreateModel() 98 | { 99 | Student model = new Student 100 | { 101 | Name = nameTextBox.Text, 102 | Phone = phoneTextBox.Text, 103 | DepartmentId = departmentComboBox.SelectedValue.ToString(), 104 | }; 105 | model.SetCommonValues(); 106 | return model; 107 | } 108 | 109 | 110 | private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) 111 | { 112 | var cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; 113 | if (cell.Value == "Delete") 114 | { 115 | bool confirmDelete = ShowDeleteAlert(); 116 | if (confirmDelete) 117 | { 118 | var id = dataGridView1.Rows[e.RowIndex].Cells["Id"].Value.ToString(); 119 | bool deleted = App.StudentService.Delete(id); 120 | LoadGridView(); 121 | MessageBox.Show(this, "Deleted", "Successful", MessageBoxButtons.OK); 122 | } 123 | } 124 | } 125 | 126 | private bool ShowDeleteAlert() 127 | { 128 | var result = MessageBox.Show(this, "Delete this?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); 129 | return result == DialogResult.Yes; 130 | } 131 | 132 | private void studentListTabPage2_Enter(object sender, EventArgs e) 133 | { 134 | LoadGridView2(); 135 | } 136 | 137 | public async Task LoadGridView2() 138 | { 139 | var result = await App.StudentService.SearchAsync(studentRequestModel); 140 | dataGridView1.DataSource = null; 141 | userControl11.DataGridView.DataSource = result.Item1.OfType().ToList().ConvertToViewableDynamicList(); 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/UserControls/UserControl1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Drawing; 5 | using System.Data; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace ConsumerWinFormsApp.UserControls 12 | { 13 | public partial class UserControl1 : UserControl 14 | { 15 | public UserControl1() 16 | { 17 | InitializeComponent(); 18 | } 19 | 20 | public DataGridView DataGridView => dataGridView1; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/UserControls/UserControl1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWinFormsApp/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace ConsumerWpfApp 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/AppFactory.cs: -------------------------------------------------------------------------------- 1 | using ApplicationLibrary; 2 | using ApplicationLibrary.Models.Departments; 3 | using ApplicationLibrary.Models.Students; 4 | using Commons.Model; 5 | using Commons.Repository; 6 | using Commons.Service; 7 | 8 | namespace ConsumerWpfApp 9 | { 10 | public static class AppFactory 11 | { 12 | static AppFactory() 13 | { 14 | StudentService = new BaseService(CreateRepository()); 15 | DepartmentService = new BaseService(CreateRepository()); 16 | } 17 | 18 | public static BaseRepository CreateRepository() where T : Entity 19 | { 20 | return new BaseRepository(BusinessDbContext.CreateInstance()); 21 | } 22 | 23 | public static BaseService StudentService { get; set; } 24 | public static BaseService DepartmentService { get; set; } 25 | } 26 | } -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/ConsumerWpfApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {031A091B-5E0A-44AB-83DC-6202BF007E8E} 8 | WinExe 9 | Properties 10 | ConsumerWpfApp 11 | ConsumerWpfApp 12 | v4.6.1 13 | 512 14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 4 16 | true 17 | 18 | 19 | AnyCPU 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | AnyCPU 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll 40 | True 41 | 42 | 43 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll 44 | True 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | MSBuild:Compile 66 | Designer 67 | 68 | 69 | MSBuild:Compile 70 | Designer 71 | 72 | 73 | App.xaml 74 | Code 75 | 76 | 77 | 78 | 79 | MainWindow.xaml 80 | Code 81 | 82 | 83 | 84 | 85 | Code 86 | 87 | 88 | True 89 | True 90 | Resources.resx 91 | 92 | 93 | True 94 | Settings.settings 95 | True 96 | 97 | 98 | ResXFileCodeGenerator 99 | Resources.Designer.cs 100 | 101 | 102 | 103 | SettingsSingleFileGenerator 104 | Settings.Designer.cs 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | {482131e7-7567-4540-bc11-7125957e7ff5} 114 | Commons 115 | 116 | 117 | {eb368842-53b0-4f00-b7a0-39d921ff9393} 118 | ApplicationLibrary 119 | 120 | 121 | 122 | 129 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/ExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using Commons.Utility; 6 | using Commons.ViewModel; 7 | using Newtonsoft.Json; 8 | 9 | namespace ConsumerWpfApp 10 | { 11 | public static class ExtensionMethods 12 | { 13 | public static List ConvertToViewableDynamicList(this List models) 14 | { 15 | Type modelType = models.First().GetType(); 16 | //you should send the IsViewable type as parameter. I didn't do this because i don't need to 17 | Type viewable = typeof(IsViewable); 18 | List propertyInfos = modelType.GetProperties().Where(x => x.CustomAttributes.Any(y => y.AttributeType == viewable)).ToList(); 19 | List list = models.Select(x => x.GetValue(propertyInfos)).ToList(); 20 | List deserializeObject = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(list)); 21 | return deserializeObject; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  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 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | using System.Windows.Data; 10 | using System.Windows.Documents; 11 | using System.Windows.Input; 12 | using System.Windows.Media; 13 | using System.Windows.Media.Imaging; 14 | using System.Windows.Navigation; 15 | using System.Windows.Shapes; 16 | using ApplicationLibrary.Models.Students; 17 | using Commons.Utility; 18 | 19 | namespace ConsumerWpfApp 20 | { 21 | /// 22 | /// Interaction logic for MainWindow.xaml 23 | /// 24 | public partial class MainWindow : Window 25 | { 26 | public MainWindow() 27 | { 28 | InitializeComponent(); 29 | this.Loaded += MainWindow_Loaded; 30 | tabControl.SelectionChanged += TabControl_SelectionChanged; 31 | 32 | } 33 | 34 | private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) 35 | { 36 | if (tabControl.SelectedIndex==0) 37 | { 38 | var x = "test"; 39 | } 40 | else 41 | { 42 | DetailsGrid.Children.Clear(); 43 | var list1 = Enum.GetNames(typeof(DayOfWeek)).ToList().Select(x => new { Name = x, Value = x }).ToList(); 44 | var list = new ObservableCollection(list1); 45 | var comboBox = CreateComboBox("test", 1, 3); 46 | comboBox.ItemsSource = list; 47 | comboBox.DisplayMemberPath = "Name"; 48 | comboBox.SelectedValuePath = "Value"; 49 | comboBox.SelectedIndex = 0; 50 | comboBox.SelectionChanged += Box1_SelectionChanged; 51 | DetailsGrid.Children.Add(comboBox); 52 | } 53 | } 54 | 55 | private void Box1_SelectionChanged(object sender, SelectionChangedEventArgs e) 56 | { 57 | ComboBox c = sender as ComboBox; 58 | var d = e.AddedItems[0] as dynamic; 59 | int i = c.SelectedIndex; 60 | } 61 | 62 | private void MainWindow_Loaded(object sender, RoutedEventArgs e) 63 | { 64 | var d = DateTime.Now; 65 | } 66 | 67 | 68 | public static ComboBox CreateComboBox(string x, int columnIndex, int rowIndex) 69 | { 70 | var element = new ComboBox() 71 | { 72 | Name = x + "ComboBox", 73 | Margin = new Thickness(5), 74 | HorizontalAlignment = HorizontalAlignment.Stretch, 75 | VerticalAlignment = VerticalAlignment.Stretch 76 | }; 77 | Grid.SetColumn(element, columnIndex); 78 | Grid.SetRow(element, rowIndex); 79 | return element; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("ConsumerWpfApp")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("ConsumerWpfApp")] 15 | [assembly: AssemblyCopyright("Copyright © 2016")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ConsumerWpfApp.Properties 12 | { 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ConsumerWpfApp.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ConsumerWpfApp.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /ConsumerApps/ConsumerWpfApp/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # GenericComponents 3 | Abstract 4 | Every application, let it be a desktop, web, mobile or any other you can image, either sends data to database or retrieves data from database to show it to the user. What if we automate the data sending and fetching process and focus only on the business logics? So that we don't need to write the common framework related hundreads of thousands lines of code for each of our projects, and the projects have been written all over the world? 5 | 6 | How you can use this library Video Playlist 7 | -------------------------------------------------------------------------------- /code-coopers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foyzulkarim/GenericComponents/ec59aaab8b0d0202576f0c93f18df3c623a10849/code-coopers.png --------------------------------------------------------------------------------