This file contains 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
@model AspNetCoreMVCMongoDBDemo.Models.Customer | |
@{ | |
Layout = "_Layout"; | |
} | |
<h4>Delete Customer</h4> | |
<div class="row"> | |
<div class="col-md-4"> | |
<form asp-action="Delete"> | |
<label class="control-label">Are you sure to delete </label> <input asp-for="CustomerId" class="form-control" readonly /> | |
<div class="form-group"> |
This file contains 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
@model AspNetCoreMVCMongoDBDemo.Models.Customer | |
@{ | |
ViewData["Title"] = "Create"; | |
} | |
<h2>Create Customer Details</h2> | |
<hr /> | |
<div class="row"> | |
<div class="col-md-4"> | |
<form asp-action="Create"> | |
<div asp-validation-summary="ModelOnly" class="text-danger"></div> |
This file contains 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
@model IEnumerable<AspNetCoreMVCMongoDBDemo.Models.Customer> | |
@{ | |
ViewData["Title"] = "Index"; | |
} | |
<h2>Index</h2> | |
<p> | |
<a asp-action="Create">Create New</a> | |
</p> | |
<table class="table table-bordered" style="width:600px"> | |
<thead> |
This file contains 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
public class HomeController : Controller | |
{ | |
private IMongoDatabase mongoDatabase; | |
//Generic method to get the mongodb database details | |
public IMongoDatabase GetMongoDatabase() | |
{ | |
var mongoClient = new MongoClient("mongodb://localhost:27017"); | |
return mongoClient.GetDatabase("CustomerDB"); | |
} |
This file contains 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
public class Customer | |
{ | |
[BsonId] | |
public ObjectId Id { get; set; } | |
[BsonElement] | |
public int CustomerId { get; set; } | |
[BsonElement] | |
public string CustomerName { get; set; } | |
[BsonElement] | |
public string Address { get; set; } |
This file contains 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
Install-Package Microsoft.EntityFrameworkCore.Tools -Version 2.0.1 | |
Install-Package MongoDB.Driver -Version 2.5.0 |
This file contains 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 Microsoft.AspNetCore.Mvc.RazorPages; | |
using Microsoft.EntityFrameworkCore; | |
namespace NetCoreRazorPageApp.Pages.Employee | |
{ |
This file contains 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
@page "{id:int}" | |
@model NetCoreRazorPageApp.Pages.Employee.DeletePageModel | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width" /> | |
<title>DeletePage</title> | |
</head> | |
<body> | |
<h4>Delete Employee Record</h4> |
This file contains 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
@page | |
@using NetCoreRazorPageApp.Model | |
@using Microsoft.EntityFrameworkCore; | |
@inject EmployeeDbContext dbcontext | |
@functions { | |
public IEnumerable<NetCoreRazorPageApp.Model.Employee> Employees { get; set; } | |
public async Task OnGetAsync() | |
{ |
This file contains 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 Microsoft.AspNetCore.Mvc.RazorPages; | |
using Microsoft.EntityFrameworkCore; | |
namespace NetCoreRazorPageApp.Pages | |
{ |