This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mkdir eKart | |
| cd eKart | |
| REM creates an empty solution | |
| dotnet new sln --name eKart | |
| REM creates a folder for .NET Core 2.1 | |
| mkdir netcore21 | |
| cd netcore21 | |
| mkdir src | |
| cd src | |
| REM creates an ASP.NET Core web api project |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace eKart.Api.Model | |
| { | |
| public class Product | |
| { | |
| [DatabaseGeneratedAttribute(DatabaseGeneratedOption.None)] | |
| public int ID { get; set; } | |
| public string Name {get; set; } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using Microsoft.EntityFrameworkCore; | |
| namespace eKart.Api.Model | |
| { | |
| public interface IDatasourceContext: IDisposable | |
| { | |
| DbSet Products{ get; set; } | |
| int SaveChanges(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using Microsoft.EntityFrameworkCore; | |
| namespace eKart.Api.Model | |
| { | |
| public class SQLServerContext: DbContext, IDatasourceContext | |
| { | |
| public SQLServerContext(DbContextOptions options):base(options) | |
| {} | |
| public DbSet Products{get; set; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using eKart.Api.Model; | |
| using Microsoft.EntityFrameworkCore; | |
| public void ConfigureServices(IServiceCollection services) | |
| { | |
| services.AddScoped<IDatasourceContext, SQLServerContext>(); | |
| services.AddDbContext(options => options.UseSqlServer(@"Server=.;Database=eKart;Trusted_Connection=True;ConnectRetryCount=0")); | |
| services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dotnet ef migrations add InitialCreate | |
| dotnet ef database update |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Threading.Tasks; | |
| using Microsoft.AspNetCore.Mvc; | |
| using eKart.Api.Model; | |
| namespace eKart.Api.Controllers | |
| { | |
| [Route("api/[controller]")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dotnet add package Swashbuckle.AspNetCore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Swashbuckle.AspNetCore.Swagger; | |
| namespace eKart.Api | |
| { | |
| public class Startup | |
| { | |
| // This method gets called by the runtime. Use this method to add services to the container. | |
| public void ConfigureServices(IServiceCollection services) | |
| { | |
| // Register the Swagger generator, defining 1 or more Swagger documents |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dotnet run --project .\netcore21\src\eKart.Api\eKart.Api.csproj | |
| dotnet run --project .\netcore21\src\eKart.Api\eKart.Api.csproj |
OlderNewer