├── code-coopers.png
├── CommonLibrary
├── Model
│ ├── BusinessConstants.cs
│ ├── packages.config
│ ├── Entity.cs
│ ├── App.config
│ ├── BusinessDbContext.cs
│ ├── Customers
│ │ └── Customer.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── Model.csproj
├── ViewModel
│ ├── packages.config
│ ├── DropdownViewModel.cs
│ ├── BaseViewModel.cs
│ ├── App.config
│ ├── Customers
│ │ └── CustomerViewModel.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── ViewModel.csproj
├── RequestModel
│ ├── packages.config
│ ├── App.config
│ ├── PartnerRequestModel.cs
│ ├── Customers
│ │ └── CustomerRequestModel.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── RequestModel.csproj
├── RepositoryLibrary
│ ├── packages.config
│ ├── App.config
│ ├── SupplierRepository.cs
│ ├── Customer
│ │ └── CustomerRepository.cs
│ ├── PaymentRepository.cs
│ ├── ProductDictionaryRepository.cs
│ ├── IGenericRepository.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── BaseRepository.cs
│ └── RepositoryLibrary.csproj
├── ServiceLibrary
│ ├── App.config
│ ├── IBaseService.cs
│ ├── packages.config
│ ├── Customers
│ │ └── CustomerService.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── ProductDictionaryService.cs
│ ├── PaymentService.cs
│ ├── BaseService.cs
│ ├── SupplierService.cs
│ └── ServiceLibrary.csproj
└── CommonLibrary.sln
├── Commons
├── Commons
│ ├── packages.config
│ ├── ViewModel
│ │ ├── IsViewable.cs
│ │ ├── DropdownViewModel.cs
│ │ └── BaseViewModel.cs
│ ├── Service
│ │ ├── IBaseService.cs
│ │ └── BaseService.cs
│ ├── Repository
│ │ ├── IGenericRepository.cs
│ │ └── BaseRepository.cs
│ ├── RequestModel
│ │ ├── ReplaceExpressionVisitor.cs
│ │ ├── ParameterRebinder.cs
│ │ ├── ExpressionHelper.cs
│ │ └── RequestHelperModels.cs
│ ├── Model
│ │ ├── Entity.cs
│ │ └── BusinessDbContext.cs
│ ├── App.config
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Utility
│ │ └── ExtensionMethods.cs
│ └── Commons.csproj
└── Commons.sln
├── ConsumerApps
├── ConsumerWpfApp
│ ├── packages.config
│ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── ExtensionMethods.cs
│ ├── AppFactory.cs
│ ├── App.config
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ └── ConsumerWpfApp.csproj
├── ApplicationLibrary
│ ├── packages.config
│ ├── Models
│ │ ├── Departments
│ │ │ ├── DepartmetnViewModel.cs
│ │ │ ├── Department.cs
│ │ │ └── DepartmentRequestModel.cs
│ │ └── Students
│ │ │ ├── Student.cs
│ │ │ ├── StudentViewModel.cs
│ │ │ └── StudentRequestModel.cs
│ ├── BusinessDbContext.cs
│ ├── App.config
│ ├── Migrations
│ │ ├── 201612030350205_StudentDepartment.Designer.cs
│ │ ├── 201612040332398_dontknowwhatischagned.Designer.cs
│ │ ├── Configuration.cs
│ │ ├── 201612040332398_dontknowwhatischagned.cs
│ │ └── 201612030350205_StudentDepartment.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── ApplicationLibrary.csproj
├── ConsumerConsoleApp
│ ├── packages.config
│ ├── App.config
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Program.cs
│ └── ConsumerConsoleApp.csproj
├── ConsumerWinFormsApp
│ ├── packages.config
│ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ ├── IGenericForm.cs
│ ├── SampleForm.cs
│ ├── UserControls
│ │ ├── UserControl1.cs
│ │ └── UserControl1.resx
│ ├── Constants.cs
│ ├── Program.cs
│ ├── App.cs
│ ├── Form1.cs
│ ├── ExtensionMethods.cs
│ ├── App.config
│ ├── SampleForm.Designer.cs
│ ├── DepartmentForm.cs
│ ├── Form1.Designer.cs
│ ├── StudentsForm.cs
│ ├── Form1.resx
│ └── SampleForm.resx
└── ConsumerApps.sln
├── README.md
├── .gitattributes
└── .gitignore
/code-coopers.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/foyzulkarim/GenericComponents/HEAD/code-coopers.png
--------------------------------------------------------------------------------
/CommonLibrary/Model/BusinessConstants.cs:
--------------------------------------------------------------------------------
1 | namespace Model
2 | {
3 | public enum CustomerType
4 | {
5 | Registered, Unregistered
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/CommonLibrary/Model/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Commons/Commons/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CommonLibrary/ViewModel/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CommonLibrary/RequestModel/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/ConsumerApps/ConsumerWpfApp/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CommonLibrary/RepositoryLibrary/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/ConsumerApps/ApplicationLibrary/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/ConsumerApps/ConsumerConsoleApp/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/ConsumerApps/ConsumerWpfApp/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/ConsumerApps/ConsumerWinFormsApp/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/CommonLibrary/RequestModel/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/CommonLibrary/ServiceLibrary/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/CommonLibrary/RepositoryLibrary/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/ConsumerApps/ConsumerWinFormsApp/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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/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/ServiceLibrary/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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/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 | }
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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/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 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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 |
--------------------------------------------------------------------------------
/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/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 | }
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/CommonLibrary/ViewModel/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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/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