Getting Started with .Net MVC c#

Using DB First Approach

Database Part MSSQL Management Studio

  • Create DB Tables,
  • Views and
  • Stored Procedure as requirement

Visual Studio Application Part

  • Create New Project
  • Create Separate Projects for DAL
  • Add Reference of DAL Project to main project
  • Add Nuget package of Entity Framework to both projects [DAL and Main]
  • Create EDMX Model from Database to project in DAL Project
  • Build Project
  • Add scaffolding Controllers of simple tables
  • Test Application

Using Code First Approach

Visual Studio Application Part

  • Create New Project
  • Create Separate Projects for DAL
  • Add Reference of DAL Project to main project
  • Add Nuget package of Entity Framework to both projects [DAL and Main]
  • Create Models and DB Context required for matching database structure
  • Build Project
  • Add scaffolding Controllers
  • Test Application

Common Try outs

  • Analysis of Bind Values, Post Variable capture
  • Necessary change implementation of code for edit method of scaffolding for adapting changes related to hidden and readonly values
  • Add Scaffolding Controllers of Complex tables which has relation/related data with another table and should show its selection in dropdown
  • Know difference between Sync and Async Methods
  • Try Master/Detail Form data entry/edit pages
  • Try Form with Checkboxes and use some nice toggle buttons for checkboxes
  • Use EditorTemplates for Create/Edit Page
  • Use DisplayTemplates for Detail/Delete Page
  • Use of TempData for message display/variable sharing between pages
  • Use of Sessions for Tracking user logins and browsing sessions
  • Use of Partial views for AJAX page result
  • use of JSON Result format for better AJAX Result
  • Use of View-Models for display of data in combined/complex page designs
  • Use of Auto-Mappers for conversion between Domain Models -> View Models and vice-versa

UI Additional Tryouts

Use of bootstrap Component like

TABS, Navs, Chosen [with ajax search], multi select-chosen, CARDS, Panels, Tooltips, Modal, fa icons, collapsible panel, accordions, date-picker, time-picker, tags

Additional Tryouts

  • Separation of DAL project with UI Project
  • Addition of BAL project in solution for application logic
  • Addition of DAL Metadata for validation and label changes
    • Direct in class Indirect using partial class which will be un-affacted in case of db-first model updates
  • Use UIHint to change display of boolean values types to nice Yes/No label in display format and toggle button in editor format
  • Customization of db query with linq for server side filtration and querying for data with criteria
  • Grouping of List data with certain members that can be helpful for report generation
  • Use of Dictionary Data type for quick access of key value data types
  • Use of Dependency Injection for Repo/Service class initialization
  • Use of Repo Class to follow repository pattern
  • Use of Service Class in BAL project to add Business Logic Layer
  • Use of try/catch and Unit or Work Pattern
  • Use of Error Logging frameworks for tracking errors of applications
  • Use of Generic Repo and Generic Services for quick application development process.

Our Basic Classes Intro

  • Use of ViewHelper for formatting number/currencies
  • Use of Flashbag for quick support of TempData
  • Use of NepaliCalendar for General Date conversion
  • Use of RestSharp Nuget Package for quick API consumption

JS Charts

  • d3 charts [pie, line, etc]

Basic Controller Variables

  • If controller is related to central only i.e it contains dbCore only it should inherit from BaseAsyncController
  • If controller is related to Organisation also i.e it contains both dbCore and dbOrg it should inherit from BaseAsyncFOController
  • While inheriting Any Controller from BaseAsyncController or BaseAsyncFOController, it should initialise base controller with respective variables also.
  • eg For BaseAsyncFOController:
using System;
 
public class DataMaintenanceController : BaseAsyncFOController
{
    #region Constructor
    public DataMaintenanceController(
        CoreAccountingMasterEntities dbCore
        , OrgAccDBEntities dbOrg
        , IErrorLog ErrorLog
        , DBHelper DBHelper
        , IAuthServices AuthService
        //,... extra
        )
    : base(dbCore, AuthService, ErrorLog, dbOrg, DBHelper)
    {
        //..extra code
    }
    #endregion
}
  • eg For BaseAsyncController
using System;
 
public class DataMaintenanceController : BaseAsyncController
{
    #region Constructor
    public DataMaintenanceController(
        CoreAccountingMasterEntities dbCore
        ,IErrorLog ErrorLog
        ,IAuthServices AuthService
        //,.. extra
        )
    : base(dbCore, AuthService, ErrorLog)
    {
        //..extra code
    }
    #endregion
}
  • The Result controller must be inside autofac config/startup file in order to make it start automatically. File: App_start/AutoFacConfig.cs
  • Code to Init Controller:
  • builder.RegisterType<DataMaintenanceController>();//.InstancePerRequest();
  • If the controller already contains variable for dbCore or dbOrg or AuthService or ErrorLog or DBHelper, then we should rename that variable to matching variable name with our BaseAsyncFOController or BaseAsyncController.
  • Our Variable Name in BaseAsyncController and BaseAsyncFOController are:
  • _dbCore, _dbOrg, _AuthService, _ErrorLog, _DBHelper
  • Also Remove base Controller variable initialisation in derived controller.