Recommended Prerequisites

Step 1 - Create a Database, Tables, and Stored Procedures.
First, we need to create a SQL Server database, tables, and stored procedure which we need to use in the application.
Here, I'm creating a database, "CoreMaster" and a table "Job".
  1. CREATE TABLE [dbo].[Job](
  2. [JobID] [int] IDENTITY(1,1) NOT NULL,
  3. [JobTitle] [nchar](250) NULL,
  4. [JobImage] [nvarchar](max) NULL,
  5. [CityId] [int] NULL,
  6. [IsActive] [bit] NULL,
  7. [CreatedBY] [nvarchar](50) NULL,
  8. [CreatedDateTime] [datetime] NULL,
  9. [UpdatedBY] [nvarchar](50) NULL,
  10. [UpdatedDateTime] [datetime] NULL,
  11. CONSTRAINT [PK_Job] PRIMARY KEY CLUSTERED
  12. (
  13. [JobID] ASC
  14. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  15. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
Now, I'm going to create stored procedures for adding job, fetching job list, and updating job.
The "Add Job" stored procedure is named "[SP_Add_Job]" which returns the inserted record's job Id.
  1. CREATE PROCEDURE [dbo].[SP_Add_Job]
  2. @JobTitle NVARCHAR(250) ,
  3. @JobImage NVARCHAR(Max) ,
  4. @CityId int ,
  5. @IsActive BIT ,
  6. @CreatedBY NVARCHAR(50) ,
  7. @CreatedDateTime DATETIME ,
  8. @UpdatedBY NVARCHAR(50),
  9. @UpdatedDateTime DATETIME
  10. AS
  11. BEGIN
  12. DECLARE @JobId as BIGINT
  13. INSERT INTO [Job]
  14. (JobTitle ,
  15. JobImage ,
  16. CityId ,
  17. IsActive ,
  18. CreatedBY ,
  19. CreatedDateTime ,
  20. UpdatedBY ,
  21. UpdatedDateTime
  22. )
  23. VALUES ( @JobTitle ,
  24. @JobImage ,
  25. @CityId ,
  26. @IsActive ,
  27. @CreatedBY ,
  28. @CreatedDateTime ,
  29. @UpdatedBY ,
  30. @UpdatedDateTime
  31. );
  32. SET @JobId = SCOPE_IDENTITY();
  33. SELECT @JobId AS JobId;
  34. END;
The "Update job" stored procedure is "[SP_Update_Job]".
  1. CREATE PROCEDURE [dbo].[SP_Update_Job]
  2. @JobId INT,
  3. @JobTitle NVARCHAR(250) ,
  4. @JobImage NVARCHAR(Max) ,
  5. @CityId INT ,
  6. @IsActive BIT ,
  7. @UpdatedBY NVARCHAR(50),
  8. @UpdatedDateTime DATETIME
  9. AS
  10. BEGIN
  11. UPDATE job
  12. SET
  13. job.JobTitle = @JobTitle,
  14. job.JobImage = @JobImage ,
  15. job.CityId = @CityId ,
  16. job.IsActive = @IsActive ,
  17. job.UpdatedBY = @UpdatedBY ,
  18. job.UpdatedDateTime = @UpdatedDateTime
  19. FROM [Job] job
  20. WHERE JobId = @JobId
  21. END;
The "Fetch job list" store procedure is [SP_Job_List].
  1. CREATE PROCEDURE [dbo].[SP_Job_List]
  2. AS
  3. BEGIN
  4. SET NOCOUNT ON;
  5. select * from [Job]
  6. END
Step 2 - Open Visual Studio 2019
Go to the Start menu on your Windows desktop and type Visual studio 2019; open it.
CRUD Operations In .NET Core 3.0 With Visual Studio 2019
Step 3 - Create a new project
The Visual Studio 2019 welcome screen will pop up, which contains four boxes on the right side.
  1. Clone or checkout code
  2. Open a project or solution
  3. Open a local folder
  4. Create a new project
From the above options, we need to click on the "Create a new project" box.
CRUD Operations In .NET Core 3.0 With Visual Studio 2019
Click on the "ASP.NET Core Web Application" and press "Next".
CRUD Operations In .NET Core 3.0 With Visual Studio 2019
From the wizard, select "Web Application (Model-View-Controller)". The framework must be selected as .NET Core 3.0. Then, click on the "OK" button.
CRUD Operations In .NET Core 3.0 With Visual Studio 2019
Put an appropriate project name and select the location where you want to create this project. Again, click the "Create" button.
CRUD Operations In .NET Core 3.0 With Visual Studio 2019
Now "Build" the project. It will install .NET Core 3.0 runtime (if it not installed on the machine).
Step 4 - Install NuGet packages.
We need to install the below packages.
  1. Microsoft.EntityFrameworkCore.SqlServer

    CRUD Operations In .NET Core 3.0 With Visual Studio 2019

  2. Microsoft.EntityFrameworkCore.SqlServer.Design

    CRUD Operations In .NET Core 3.0 With Visual Studio 2019

  3. Microsoft.EntityFrameworkCore.Tools

    CRUD Operations In .NET Core 3.0 With Visual Studio 2019

  4. Dapper

    CRUD Operations In .NET Core 3.0 With Visual Studio 2019
Step 5 - Create Dapper Class and Interface
Now, create two folders -
  1. Helper
  2. Interface
In the Interface folder, add a new interface namely "IDapperHelper" and copy the below code and paste in that class.
  1. using Dapper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.Common;
  6. using System.Linq;
  7. using System.Linq.Expressions;
  8. using System.Threading.Tasks;
  9. namespace CoreDemo_3_0.Interfaces
  10. {
  11. public interface IDapperHelper : IDisposable
  12. {
  13. DbConnection GetConnection();
  14. T Get<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure);
  15. List<T> GetAll<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure);
  16. int Execute(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure);
  17. T Insert<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure);
  18. T Update<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure);
  19. }
  20. }
In the Helper folder, add a new class namely "DapperHelper" and copy the below code and paste in that class.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Dapper;
  5. using Microsoft.Extensions.Configuration;
  6. using System.Data;
  7. using System.Data.Common;
  8. using System.Data.SqlClient;
  9. using System.Linq.Expressions;
  10. using static Dapper.SqlMapper;
  11. using CoreDemo_3_0.Interfaces;
  12. namespace CoreDemo_3_0.Helper
  13. {
  14. public class DapperHelper : IDapperHelper
  15. {
  16. private readonly IConfiguration _config;
  17. public DapperHelper(IConfiguration config)
  18. {
  19. _config = config;
  20. }
  21. public DbConnection GetConnection()
  22. {
  23. return new SqlConnection(_config.GetConnectionString("DefaultConnection"));
  24. }
  25. public T Get<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure)
  26. {
  27. using (IDbConnection db = new SqlConnection(_config.GetConnectionString("DefaultConnection")))
  28. {
  29. return db.Query<T>(sp, parms, commandType: commandType).FirstOrDefault();
  30. }
  31. }
  32. public List<T> GetAll<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure)
  33. {
  34. using (IDbConnection db = new SqlConnection(_config.GetConnectionString("DefaultConnection")))
  35. {
  36. return db.Query<T>(sp, parms, commandType: commandType).ToList();
  37. }
  38. }
  39. public int Execute(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure)
  40. {
  41. using (IDbConnection db = new SqlConnection(_config.GetConnectionString("DefaultConnection")))
  42. {
  43. return db.Execute(sp, parms, commandType: commandType);
  44. }
  45. }
  46. public T Insert<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure)
  47. {
  48. T result;
  49. using (IDbConnection db = new SqlConnection(_config.GetConnectionString("DefaultConnection")))
  50. {
  51. try
  52. {
  53. if (db.State == ConnectionState.Closed)
  54. db.Open();
  55. using (var tran = db.BeginTransaction())
  56. {
  57. try
  58. {
  59. result = db.Query<T>(sp, parms, commandType: commandType, transaction: tran).FirstOrDefault();
  60. tran.Commit();
  61. }
  62. catch (Exception ex)
  63. {
  64. tran.Rollback();
  65. throw ex;
  66. }
  67. }
  68. }
  69. catch (Exception ex)
  70. {
  71. throw ex;
  72. }
  73. finally
  74. {
  75. if (db.State == ConnectionState.Open)
  76. db.Close();
  77. }
  78. return result;
  79. }
  80. }
  81. public T Update<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure)
  82. {
  83. T result;
  84. using (IDbConnection db = new SqlConnection(_config.GetConnectionString("DefaultConnection")))
  85. {
  86. try
  87. {
  88. if (db.State == ConnectionState.Closed)
  89. db.Open();
  90. using (var tran = db.BeginTransaction())
  91. {
  92. try
  93. {
  94. result = db.Query<T>(sp, parms, commandType: commandType, transaction: tran).FirstOrDefault();
  95. tran.Commit();
  96. }
  97. catch (Exception ex)
  98. {
  99. tran.Rollback();
  100. throw ex;
  101. }
  102. }
  103. }
  104. catch (Exception ex)
  105. {
  106. throw ex;
  107. }
  108. finally
  109. {
  110. if (db.State == ConnectionState.Open)
  111. db.Close();
  112. }
  113. return result;
  114. }
  115. }
  116. public void Dispose()
  117. {
  118. throw new NotImplementedException();
  119. }
  120. }
  121. }

Here, we created a Dapper helper which we will use to communicate with the database.

Step 6 - Create a Context class
Create a new folder named "Context" and add one class "DataContext" which extends from the DbContext class.
Copy the below code and paste inside "DataContext" class.
  1. using CoreDemo_3_0.Entities;
  2. using Microsoft.EntityFrameworkCore;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. namespace CoreDemo_3_0.Context
  8. {
  9. public class DataContext : DbContext
  10. {
  11. public DataContext() { }
  12. public DataContext(DbContextOptions<DataContext> options) : base(options) { }
  13. }
  14. }
Step 7
Create one folder named "Entities" and add a class, namely "Job".
Copy the below code and paste into the "Job" class.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. namespace CoreDemo_3_0.Entities
  7. {
  8. public class Job
  9. {
  10. [Key]
  11. public int JobID { get; set; }
  12. public string JobTitle { get; set; }
  13. public int CityId { get; set; }
  14. public string JobImage { get; set; }
  15. public bool IsActive { get; set; }
  16. public string CreatedBY { get; set; }
  17. public DateTime? CreatedDateTime { get; set; }
  18. public string UpdatedBY { get; set; }
  19. public DateTime? UpdatedDateTime { get; set; }
  20. }
  21. }
Step 8
Create one folder named "Models" and add a class "JobModel".

Copy the below code and paste into "JobModel" class.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. namespace CoreDemo_3_0.Models
  6. {
  7. public class JobModel
  8. {
  9. public int JobID { get; set; }
  10. public string JobTitle { get; set; }
  11. public int CityId { get; set; }
  12. public string JobImage { get; set; }
  13. public bool IsActive { get; set; }
  14. public string CreatedBY { get; set; }
  15. public DateTime? CreatedDateTime { get; set; }
  16. public string UpdatedBY { get; set; }
  17. public DateTime? UpdatedDateTime { get; set; }
  18. public int JobState { get; set; }
  19. }
  20. }

Step 9 - Add IJob interface

Add IJob interface, "IJobService" inside the interface folder which we created before. Below is the code of the interface.
  1. using CoreDemo_3_0.Entities;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. namespace CoreDemo_3_0.Interfaces
  7. {
  8. public interface IJobService
  9. {
  10. int Delete(int JobId);
  11. Job GetByJobId(int JobId);
  12. string Update(Job job);
  13. int Create(Job JobDetails);
  14. List<Job> ListAll();
  15. }
  16. }

Step 10 - Add Job service

Add a new folder named "Services" and one class inside that folder. The class name will be "JobService". Below is the JobService class code.
  1. using CoreDemo_3_0.Entities;
  2. using CoreDemo_3_0.Interfaces;
  3. using Dapper;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using System.Transactions;
  10. namespace CoreDemo_3_0.Services
  11. {
  12. public class JobService : IJobService
  13. {
  14. private readonly IDapperHelper _dapperHelper;
  15. public JobService(IDapperHelper dapperHelper)
  16. {
  17. this._dapperHelper = dapperHelper;
  18. }
  19. public int Create(Job job)
  20. {
  21. var dbPara = new DynamicParameters();
  22. dbPara.Add("JobTitle", job.JobTitle, DbType.String);
  23. dbPara.Add("JobImage", job.JobImage, DbType.String);
  24. dbPara.Add("CityId", job.CityId, DbType.Int32);
  25. dbPara.Add("IsActive", job.IsActive, DbType.String);
  26. dbPara.Add("CreatedBY", "1", DbType.String);
  27. dbPara.Add("CreatedDateTime", DateTime.Now, DbType.DateTime);
  28. dbPara.Add("UpdatedBY", "1", DbType.String);
  29. dbPara.Add("UpdatedDateTime", DateTime.Now, DbType.DateTime);
  30. #region using dapper
  31. var data = _dapperHelper.Insert<int>("[dbo].[SP_Add_Job]",
  32. dbPara,
  33. commandType: CommandType.StoredProcedure);
  34. return data;
  35. #endregion
  36. }
  37. public Job GetByJobId(int JobId)
  38. {
  39. #region using dapper
  40. var data = _dapperHelper.Get<Job>($"select * from job where JobId={JobId}", null,
  41. commandType: CommandType.Text);
  42. return data;
  43. #endregion
  44. }
  45. public int Delete(int JobId)
  46. {
  47. var data = _dapperHelper.Execute($"Delete [Job] where JObId={JobId}", null,
  48. commandType: CommandType.Text);
  49. return data;
  50. }
  51. public List<Job> ListAll()
  52. {
  53. var data = _dapperHelper.GetAll<Job>("[dbo].[SP_Job_List]", null, commandType: CommandType.StoredProcedure);
  54. return data.ToList();
  55. }
  56. public string Update(Job job)
  57. {
  58. var dbPara = new DynamicParameters();
  59. dbPara.Add("JobTitle", job.JobTitle, DbType.String);
  60. dbPara.Add("JobId", job.JobID);
  61. dbPara.Add("JobImage", job.JobImage, DbType.String);
  62. dbPara.Add("CityId", job.CityId, DbType.Int32);
  63. dbPara.Add("IsActive", job.IsActive, DbType.String);
  64. dbPara.Add("UpdatedBY", "1", DbType.String);
  65. dbPara.Add("UpdatedDateTime", DateTime.Now, DbType.DateTime);
  66. var data = _dapperHelper.Update<string>("[dbo].[SP_Update_Job]",
  67. dbPara,
  68. commandType: CommandType.StoredProcedure);
  69. return data;
  70. }
  71. }
  72. }
Step 11 - Add Connection String
Add a connection string into the appsettings.json file. Here is the code of the appsettings.json file.
  1. {
  2. "ConnectionStrings": {
  3. "DefaultConnection": "data source=.;initial catalog=CoreMaster;User Id=sa;Password=******;"
  4. },
  5. "Logging": {
  6. "LogLevel": {
  7. "Default": "Warning",
  8. "Microsoft.Hosting.Lifetime": "Information"
  9. }
  10. },
  11. "AllowedHosts": "*"
  12. }
Step 12 - Changes in Startup class
Now, we need to add a connection string context and register our services.
Code to add connectionstring -
  1. services.AddDbContext<DataContext>(options =>
  2. options.UseSqlServer(
  3. Configuration.GetConnectionString("DefaultConnection")));
Add a service to scoped.
  1. //Job service
  2. services.AddScoped<IJobService, JobService>();
  3. //Register dapper in scope
  4. services.AddScoped<IDapperHelper, DapperHelper>();
Step 13 - Add Controller
It's now time to add a Job Controller inside the Controllers folder. Below is the full code of JobController.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net.Http.Headers;
  6. using System.Threading.Tasks;
  7. using CoreDemo_3_0.Entities;
  8. using CoreDemo_3_0.Interfaces;
  9. using CoreDemo_3_0.Models;
  10. using Microsoft.AspNetCore.Hosting;
  11. using Microsoft.AspNetCore.Mvc;
  12. namespace CoreDemo_3_0.Controllers
  13. {
  14. public class JobController : Controller
  15. {
  16. private readonly IJobService _jobManager;
  17. private readonly IHostingEnvironment _hostingEnvironment;
  18. public JobController(IJobService jobManager, IHostingEnvironment hostingEnvironment)
  19. {
  20. _jobManager = jobManager;
  21. _hostingEnvironment = hostingEnvironment;
  22. }
  23. public ActionResult Index()
  24. {
  25. var data = _jobManager.ListAll();
  26. string baseUrl = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}";
  27. foreach (var item in data)
  28. {
  29. if (!string.IsNullOrEmpty(item.JobImage))
  30. item.JobImage = Path.Combine(baseUrl, "Images", item.JobImage);
  31. else
  32. item.JobImage = Path.Combine(baseUrl, "Images", "404.png");
  33. }
  34. return View(data);
  35. }
  36. #region Add Job
  37. public ActionResult Add()
  38. {
  39. return View("Form", new JobModel());
  40. }
  41. [HttpPost]
  42. [ValidateAntiForgeryToken]
  43. public ActionResult Add(JobModel model)
  44. {
  45. if (ModelState.IsValid)
  46. {
  47. var fileName = "";
  48. if (Request.Form.Files.Count > 0)
  49. {
  50. var file = Request.Form.Files[0];
  51. var webRootPath = _hostingEnvironment.WebRootPath;
  52. var newPath = Path.Combine(webRootPath, "images");
  53. if (!Directory.Exists(newPath)) Directory.CreateDirectory(newPath);
  54. if (file.Length > 0)
  55. {
  56. fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
  57. var fullPath = Path.Combine(newPath, fileName);
  58. using (var stream = new FileStream(fullPath, FileMode.Create))
  59. {
  60. file.CopyTo(stream);
  61. }
  62. }
  63. }
  64. var job = new Job()
  65. {
  66. CityId = model.CityId,
  67. JobImage = fileName,
  68. CreatedBY = "1",
  69. CreatedDateTime = DateTime.Now,
  70. JobTitle = model.JobTitle,
  71. UpdatedBY = "1",
  72. IsActive = model.IsActive,
  73. UpdatedDateTime = DateTime.Now
  74. };
  75. _jobManager.Create(job);
  76. return RedirectToAction("Index", "Job");
  77. }
  78. return View("Form", model);
  79. }
  80. #endregion
  81. #region Edit Job
  82. public ActionResult Edit(int JobId)
  83. {
  84. var jobEntity = _jobManager.GetByJobId(JobId);
  85. var jobModel = new JobModel
  86. {
  87. JobID = jobEntity.JobID,
  88. CityId = jobEntity.CityId,
  89. JobImage = jobEntity.JobImage,
  90. CreatedBY = jobEntity.CreatedBY,
  91. CreatedDateTime = jobEntity.CreatedDateTime,
  92. JobTitle = jobEntity.JobTitle,
  93. UpdatedBY = jobEntity.UpdatedBY,
  94. IsActive = jobEntity.IsActive,
  95. UpdatedDateTime = jobEntity.UpdatedDateTime
  96. };
  97. return View("Form", jobModel);
  98. }
  99. [HttpPost]
  100. [ValidateAntiForgeryToken]
  101. public ActionResult Edit(JobModel model)
  102. {
  103. if (ModelState.IsValid)
  104. {
  105. var fileName = model.JobImage ?? "";
  106. if (Request.Form.Files.Count > 0)
  107. {
  108. var file = Request.Form.Files[0];
  109. var webRootPath = _hostingEnvironment.WebRootPath;
  110. var newPath = Path.Combine(webRootPath, "images");
  111. if (!Directory.Exists(newPath)) Directory.CreateDirectory(newPath);
  112. if (file.Length > 0)
  113. {
  114. fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
  115. var fullPath = Path.Combine(newPath, fileName);
  116. using (var stream = new FileStream(fullPath, FileMode.Create))
  117. {
  118. file.CopyTo(stream);
  119. }
  120. }
  121. }
  122. var job = new Job()
  123. {
  124. JobID = model.JobID,
  125. CityId = model.CityId,
  126. JobImage = fileName,
  127. JobTitle = model.JobTitle,
  128. UpdatedBY = "1",
  129. IsActive = model.IsActive,
  130. };
  131. _jobManager.Update(job);
  132. return RedirectToAction("Index", "Job");
  133. }
  134. return View("Form", model);
  135. }
  136. #endregion
  137. #region Delete Job
  138. public ActionResult Delete(int JobId)
  139. {
  140. var jobEntity = _jobManager.Delete(JobId);
  141. return RedirectToAction("Index", "Job");
  142. }
  143. #endregion
  144. }
  145. }
Step 14 - Add Views
It is time to add a ViewController inside Views > Job folder. Below is the code for all views of JobController.
Form.cshtml
  1. @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
  2. @model CoreDemo_3_0.Models.JobModel
  3. @{
  4. ViewData["Title"] = "Add Job";
  5. Layout = "~/Views/Shared/_Layout.cshtml";
  6. }
  7. <div class="row">
  8. <!-- left column -->
  9. <div class="col-md-12">
  10. <!-- general form elements -->
  11. <div class="box box-primary">
  12. <!-- form start -->
  13. @using (Html.BeginForm(Model.JobID == 0 ? "Add" : "Edit", "Job", FormMethod.Post, new { enctype = "multipart/form-data" }))
  14. {
  15. <div class="box-body">
  16. @Html.AntiForgeryToken()
  17. <div class="row">
  18. @Html.HiddenFor(model => model.JobID)
  19. <div class="col-xs-12" f>
  20. <label>Job Title</label>
  21. @Html.TextBoxFor(model => model.JobTitle, new { @class = "form-control", @placeholder = "Job Title" })
  22. </div>
  23. </div>
  24. <br />
  25. <div class="row">
  26. <div class="col-xs-12">
  27. <label>Enter City ID</label>
  28. @Html.TextBoxFor(model => model.CityId, new { @class = "form-control" })
  29. </div>
  30. </div>
  31. <br />
  32. <div class="row">
  33. <div class="col-xs-12">
  34. <label>Job Image</label>
  35. <input type="file" id="file" name="file">
  36. @Html.HiddenFor(model => model.JobImage)
  37. </div>
  38. </div>
  39. <div class="row">
  40. <div class="col-xs-12">
  41. @Html.CheckBoxFor(model => model.IsActive, new { @class = "col-form-checkbox" }) Vacancy Available
  42. </div>
  43. </div>
  44. </div><!-- /.box-body -->
  45. <div class="box-footer">
  46. <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Save</button>
  47. </div>
  48. }
  49. </div>
  50. </div>
  51. </div>
Index.cshtml
  1. @model List<CoreDemo_3_0.Entities.Job>
  2. @{
  3. ViewData["Title"] = "Job List";
  4. }
  5. <a href="/Job/Add" class="btn btn-primary">Add</a>
  6. <br />
  7. <table id="_DataTable" class="table compact table-striped table-bordered nowrap dataTable" aria-describedby="_DataTable_info">
  8. <thead>
  9. <tr role="row">
  10. <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="_DataTable" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Image: activate to sort column descending" style="width: 127px;">Image</th>
  11. <th class="sorting" role="columnheader" tabindex="0" aria-controls="_DataTable" rowspan="1" colspan="1" aria-label="Title: activate to sort column ascending" style="width: 209px;">Title</th>
  12. <th class="sorting" role="columnheader" tabindex="0" aria-controls="_DataTable" rowspan="1" colspan="1" aria-label="City: activate to sort column ascending" style="width: 116px;">City</th>
  13. <th class="sorting" role="columnheader" tabindex="0" aria-controls="_DataTable" rowspan="1" colspan="1" aria-label="Vacancy: activate to sort column ascending" style="width: 127px;">Vacancy</th>
  14. <th class="sorting" role="columnheader" tabindex="0" aria-controls="_DataTable" rowspan="1" colspan="1" aria-label="Created Date: activate to sort column ascending" style="width: 190px;">Created Date</th>
  15. <th style="width: 38px;" class="sorting" role="columnheader" tabindex="0" aria-controls="_DataTable" rowspan="1" colspan="1" aria-label=" Action : activate to sort column ascending"> Action </th>
  16. </tr>
  17. </thead>
  18. <tbody role="alert" aria-live="polite" aria-relevant="all">
  19. @foreach (var item in Model)
  20. {
  21. <tr class="even">
  22. <td style="text-align:left"><img src="@item.JobImage" alt="Image" width="50" height="50"></td>
  23. <td style="text-align:left">@item.JobTitle</td>
  24. <td style="text-align:left">@item.CityId</td>
  25. <td style="text-align:left">@(item.IsActive == true ? "Yes" : "No")</td>
  26. <td style="text-align:right">@item.CreatedDateTime</td>
  27. <td class="text-center ">
  28. <a href="/Job/[email protected]" title="Edit">Edit <i class="fa fa-edit"></i></a><a href="/Job/Delete?&[email protected]" class="" onclick="return confirm(" Are you sure you want to delete this job?");" title="Delete">Delete <i class="fa fa-times"></i></a>
  29. </td>
  30. </tr>
  31. }
  32. </tbody>
  33. </table>

Output

  1. Index Page

    CRUD Operations In .NET Core 3.0 With Visual Studio 2019

  2. Add Page

    CRUD Operations In .NET Core 3.0 With Visual Studio 2019

  3. Edit Page

    CRUD Operations In .NET Core 3.0 With Visual Studio 2019

Summary

Here, we created a simple application that uses the dapper, Core 3.0 preview, SQL Server, and Visual Studio 2019 to perform CRUD operations. You can leave the feedback/comment/questions about this article below. Please let me know how you like and understand this article and how I could improve it.