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.
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
Post a Comment