Skip to main content

ASP.NET Core Configuration

Create a Solution in Visual Studio 2022

 I.   Create a Blank Solution in Visual Studio 2022 (Ecommerce)

 II.   In the Solution Add a new Project except for Individual Account authentication with Https Required/not required (Ecommerce. UI)  

                 a.Required NuGet packages

                        i.   Microsoft.EntityFrameworkCore.SqlServer—6.0.9

                       ii.   CreateArea[Admin and Customer                    

      III.            Add a new Class Library Project in the Solution (Ecommerce. Models)

     IV.            Add a new Class Library Project in the Solution (Ecommerce.DataAccess)

a.       Required NuGet Packages:

                                                                i.      Microsoft.AspNetCore.Identity.EntityFrameworkCore—6.0.9[stable]

                                                                 ii.       Microsoft.EntityFrameworkCore.Tools—6.0.9[Stable]-Migration package

                                                                 iii.   Microsoft.EntityFrameworkCore.Relational—6.0.9[Stable]Migration package

                                                                 iv.   Microsoft.EntityFrameworkCore.Design—6.0.9[Stable]MigrationPackage

                                                                  v.  Currently the project developed in 6.0 framework that why we are using in 6.0.9 NuGet Packages

       V.            Add a new Class Library Project In the solution (Ecommerce. Utility)


Create Models/Entity in the Class Library Project

public class Category

                     {

                    [Key]

                    public int Id { get; set; }

                    [Required]

                    public string Name { get; set; }

                    [DisplayName("Display Order")]

                       public int DisplayOrder { get; set; }

                       public DateTime  CreatedDateTime { get; set; }=DateTime.Now;

                    }

Note:

[Key] Annotation is used for Create a primary key column

[Required] Annotation is used for Create a NOT NULL Column in database

[DisplayName] Annotation/Attribute is used to create default conventions and create a Display Order column instead of the DisplayOrder column in the Category 

[ValidateNever] Indicates that a property or parameter should be excluded from validation.

https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?source=recommendations&view=aspnetcore-7.0

public  class Product

                 {

                 public int Id { get; set; }

                 [Required]

                 public string Name { get; set; }

                 [Required]

                 public string Description { get; set; }

                 [Required]

                 public double Price { get; set; }

                 [ValidateNever]

                 public string ImageUrl { get; set; }

                 public int CategoryId { get; set; }

                 [ValidateNever]

                 public Category Category { get; set; }

                  //A product have single Catgeory so 1 to many relation mapping

                 }


Ecommerce.DataAccess

 

public  class ApplicationDbContext:IdentityDbContext

{

                                  public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)

                                  :base(options)

                                 { }

                                  public DbSet<Category> Categories { get; set; }

                                  public DbSet<Product> Products { get; set; }

}

 Ecommerce. UI

    SQL Connection Configuration

builder.Services.AddDbContext<ApplicationDbContext>(options =>

{

                                  options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"));

});

    Area Configuration &Routing

app.MapControllerRoute(

              name: "default",

            pattern: "{area=User}/{controller=Home}/{action=Index}/{id?}");

Ecommerce. WEB

               

                                i.            Add Area in the Project Right-Click the project -NewScafoddingItem-Area [Admin & Customer] and remove the Data and Model Folder

                              ii.            Add Boot-swatch Theme in the project - https://bootswatch.com/

a.       Add the Download Theme css in the wwwroot-cssfolder

b.      Replace the existing BootstrapCss with addednewcss in _layoutPage

c.       Run the project with UI is the startup one.



Comments

Popular posts from this blog

Re-sharper Trial Expires Re-usability- Tricks

Re-sharper Trial Expires Re-usability-  Tricks  Re sharper It is a popular developer productivity extension for Microsoft Visual Studio. It automates most of what can be automated in your coding routines. It finds compiler errors, run-time errors, redundancies, and code smells right as you type, suggesting intelligent corrections for them. Note: This document describes precise after the trial expiry of the re-sharper how we can configure on Next 30 Days validity Pros:Development must easier while loading all the Re-sharper Components; Configuration: Uninstall the application from the Control Panel Remove the system Registry entry default Parameter from the below location-HKEY_CURRENT_USER/Softwares/JetBrains(delete the jetbrains folder) Remove the PrgrammeDataFolder behind the sub folder JetBrains Remove the User AppData folder. For all the use cases Done user can restart the Machine After that user able to  Re-install the application to validate  n

How to capture the log using USB Lyzer

1.       Here you can see to which port your device is connected in the “Device Tree” tab on the left side. You have to check the boxes for which device you need to capture the logs. For example: I have connected the device in port2 and so the device is listed under port2. In order to capture logs of that device, you have to select all the check boxes of the device listed under the specific port.