Template Web API with individual user accounts and without, ninject, automapper set up.
- Open solution in VS
- Replace in files - TemplateWebApi with the desired name
- Rename the solution and all the projects - replacing TemplateWebApi with the desired name
- Rename all default namespaces and assembly names in all projects properties - replacing TemplateWebApi with the desired name
- Close VS
- Rename all the projects folders in Windows - replacing TemplateWebApi with the desired name
- Start the solution in VS
- All the projects can not be found
- Remove the project one by one and Add Existing Project to the folders by navigating to the desired one
- Select Web.Api to be starting project
- Delete all bin, obj and packages folders
- Build, Start, Done
- Delete all bin, obj and packages folders - if something breaks, delete them again and restart the solution
- If you do not follow the steps references will not be saved. They are:
- TemplateWebApi.Common - none
- TemplateWebApi.Data - TemplateWebApi.Data.Models
- TemplateWebApi.Data.Common - TemplateWebApi.Data
- TemplateWebApi.Data.Models - none
- TemplateWebApi.Services.Data - TemplateWebApi.Data.Common, TemplateWebApi.Data.Models
- TemplateWebApi.Web.Api - all
- TemplateWebApi.Web.Infrastructure - none
- Blank Solution - the name of the app
- Folders - Data, Services, Web
- Generating Projects
- for Data - where browse to add \Data
- the name of the app.Data
- the name of the app.Models
- for Data - where browse to add \Data
-
Delete
- Scripts
- Views
- Fonts
- Areas
- AppData
- Content
- favicon
- Project Readme
- Bundle Config
- Filter Config
- Route Config
- Home Controller
- Values Controller???
-
After build removing the unused from Global.asax
-
From IdentityModels extract ApplicationUser to Data.Models
-
Adding through Manage NuGet for solution adding EntityFramework and Microsoft.AspNet.Identity.EntityFramework for Data.Models and Data
-
Adding references after build
-
From IdentityModels extract ApplicationDbContext to Data
-
Fix Usings and References
-
Delete IdentityModels
-
Package Manager Console - enable-migrations for Data
-
Making public static class DatabaseConfig in App_Start with namespace without App_Start at the end
-
In DatabaseConfig -
public static void Initialize() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<ApplicationDbContext, Configuration>()); } and fix the Configuration class into Migrations to be public -
Global.asax - DatabaseConfig.Initialize();
-
DatabaseConfig - Initialize - ApplicationDbContext.Create().Database.Initialize(true);
-
WebConfig - fixing connectionString
-
IdentityConfig - for password length and so on
-
For registering: POST - localhost:(your api)/api/Account/Register Headers - Content-Type - application/json Body - raw JSON - {"email":"ahansb@mail.com", "password":"123456", "confirmPassword":"123456"}
-
For getting authorization: POST - localhost:(your api)/Token Body - x-www-form-urlencoded username ahansb@mail.com password 123456 grant_type password Access Token is received after the post of type Bearer
-
AccountBindingModels - extract all classes with the same namespace
-
AccountViewModels - extract all classes with the same namespace
-
Fix all using in namespaces
-
Adding Data.Common - with GenericRepository copy/paste from old projects and in Contracts IGenericRepository
-
Adding in Services\TemplateWebApi.Services.Data
-
Adding in Data.Models template object with user and in ApplicationUser collection ot templates. Adding Templates into ApplicationDbContext.
-
Adding new TemplateController - Web API 2 Controller with actions, using Entity Framework. Adding [Authorization]
-
Adding Project View Models - TemplateReques and Response view models
-
Adding in Services.Data TemplatesService and ITemplatesService
-
Installing Ninject.Web.WebApi.WebHost in Web.Api
-
In NinjectWebCommon in RegisterServices - kernel.Bind().To();
-
Adiing in TemplatesService and ITemplatesService Add function
-
After Exception in NinjectWebCommon updating all 4 ninject
-
If exception when try to start - Multiple object sets per type are not supported. The object sets 'ApplicationUsers' and 'Users' can both contain instances of type 'TemplateWebApi.Data.Models.ApplicationUser'., remove in ApplicationDbContext - public System.Data.Entity.DbSet<TemplateWebApi.Data.Models.ApplicationUser> ApplicationUsers { get; set; }
-
Copy paste ninject register services -
-
Adding IApplicationDbContext
-
Adding through nuget ninject.extensions.conventions
-
Adding using Ninject.Extensions.Conventions; in NinjectWebCommon
-
Adding new project TemplateWebApi.Common with constants for assemblies
-
In Repository to use IApplicationDbContext not DbContext and property Context
-
Fixing TemplatesController with TemplatesService
-
Installing Automapper in Web.API
-
Making new project TemplateWebApi.Web.Infrastructure with mappings folder and installing Automapper:
- AutomapperConfig
- IHaveCustomMappings
- IMapFrom
- IMapTo
- QueryableExtensions
-
Register in Global.asax Automapper - var autoMapperConfig = new AutoMapperConfig(); autoMapperConfig.Execute(Assembly.GetExecutingAssembly());
-
Making BaseController for automapper
-
TemplatesController implement with automapper