second commit
This commit is contained in:
parent
0455f3c2c8
commit
abcc068472
44
foodapp/Controllers/FoodItemsController
Normal file
44
foodapp/Controllers/FoodItemsController
Normal file
@ -0,0 +1,44 @@
|
||||
using FoodApp.Data;
|
||||
using FoodApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
[Route("FoodItems")]
|
||||
public class FoodItemsController : Controller
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public FoodItemsController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: FoodItems
|
||||
public IActionResult Index()
|
||||
{
|
||||
return Content("This is the FoodItems index page.");
|
||||
// var foodItems = _context.FoodItems.ToList();
|
||||
// return View(foodItems);
|
||||
}
|
||||
|
||||
// GET: FoodItems/Create
|
||||
public IActionResult Create()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
// POST: FoodItems/Create
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> Create([Bind("Id,Name,Description")] FoodItem foodItem)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
_context.Add(foodItem);
|
||||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
return View(foodItem);
|
||||
}
|
||||
}
|
15
foodapp/Data/ApplicationDbContext.cs
Normal file
15
foodapp/Data/ApplicationDbContext.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using FoodApp.Models;
|
||||
|
||||
namespace FoodApp.Data
|
||||
{
|
||||
public class ApplicationDbContext : DbContext
|
||||
{
|
||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<FoodItem> FoodItems { get; set; }
|
||||
}
|
||||
}
|
24
foodapp/Data/DesignTimeDbContextFactory.cs
Normal file
24
foodapp/Data/DesignTimeDbContextFactory.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.IO;
|
||||
|
||||
namespace FoodApp.Data
|
||||
{
|
||||
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
|
||||
{
|
||||
public ApplicationDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
IConfigurationRoot configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
|
||||
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
|
||||
var connectionString = configuration.GetConnectionString("DefaultConnection");
|
||||
builder.UseMySql(connectionString, new MySqlServerVersion(new Version(8, 0, 21)));
|
||||
|
||||
return new ApplicationDbContext(builder.Options);
|
||||
}
|
||||
}
|
||||
}
|
20
foodapp/Dockerfile
Normal file
20
foodapp/Dockerfile
Normal file
@ -0,0 +1,20 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["CloudApp.csproj", "./"]
|
||||
RUN dotnet restore "CloudApp.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/."
|
||||
RUN dotnet build "CloudApp.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "CloudApp.csproj" -c Release -o /app/publish
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "CloudApp.dll"]
|
50
foodapp/Migrations/20240511061657_AddFoodItem.Designer.cs
generated
Normal file
50
foodapp/Migrations/20240511061657_AddFoodItem.Designer.cs
generated
Normal file
@ -0,0 +1,50 @@
|
||||
// <auto-generated />
|
||||
using FoodApp.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace foodapp.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20240511061657_AddFoodItem")]
|
||||
partial class AddFoodItem
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FoodApp.Models.FoodItem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("FoodItems");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
42
foodapp/Migrations/20240511061657_AddFoodItem.cs
Normal file
42
foodapp/Migrations/20240511061657_AddFoodItem.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace foodapp.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddFoodItem : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterDatabase()
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "FoodItems",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Name = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
Description = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_FoodItems", x => x.Id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "FoodItems");
|
||||
}
|
||||
}
|
||||
}
|
47
foodapp/Migrations/ApplicationDbContextModelSnapshot.cs
Normal file
47
foodapp/Migrations/ApplicationDbContextModelSnapshot.cs
Normal file
@ -0,0 +1,47 @@
|
||||
// <auto-generated />
|
||||
using FoodApp.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace foodapp.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FoodApp.Models.FoodItem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("FoodItems");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
9
foodapp/Models/FoodItem.cs
Normal file
9
foodapp/Models/FoodItem.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace FoodApp.Models
|
||||
{
|
||||
public class FoodItem
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
}
|
||||
}
|
26
foodapp/Pages/Error.cshtml
Normal file
26
foodapp/Pages/Error.cshtml
Normal file
@ -0,0 +1,26 @@
|
||||
@page
|
||||
@model ErrorModel
|
||||
@{
|
||||
ViewData["Title"] = "Error";
|
||||
}
|
||||
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
|
||||
</p>
|
||||
<p>
|
||||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
||||
It can result in displaying sensitive information from exceptions to end users.
|
||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||
and restarting the app.
|
||||
</p>
|
27
foodapp/Pages/Error.cshtml.cs
Normal file
27
foodapp/Pages/Error.cshtml.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace foodapp.Pages;
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public class ErrorModel : PageModel
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
private readonly ILogger<ErrorModel> _logger;
|
||||
|
||||
public ErrorModel(ILogger<ErrorModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||
}
|
||||
}
|
||||
|
26
foodapp/Pages/Index.cshtml
Normal file
26
foodapp/Pages/Index.cshtml
Normal file
@ -0,0 +1,26 @@
|
||||
@page
|
||||
@model FoodApp.Models.FoodItem
|
||||
|
||||
<h1>Add New Food Item</h1>
|
||||
|
||||
<form asp-action="Create">
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Name" class="control-label"></label>
|
||||
<input asp-for="Name" class="form-control" />
|
||||
<span asp-validation-for="Name" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Description" class="control-label"></label>
|
||||
<input asp-for="Description" class="form-control" />
|
||||
<span asp-validation-for="Description" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="submit" value="Create" class="btn btn-primary" />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div>
|
||||
<a asp-action="Index">Back to List</a>
|
||||
</div>
|
||||
|
19
foodapp/Pages/Index.cshtml.cs
Normal file
19
foodapp/Pages/Index.cshtml.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace foodapp.Pages;
|
||||
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private readonly ILogger<IndexModel> _logger;
|
||||
|
||||
public IndexModel(ILogger<IndexModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
8
foodapp/Pages/Privacy.cshtml
Normal file
8
foodapp/Pages/Privacy.cshtml
Normal file
@ -0,0 +1,8 @@
|
||||
@page
|
||||
@model PrivacyModel
|
||||
@{
|
||||
ViewData["Title"] = "Privacy Policy";
|
||||
}
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<p>Use this page to detail your site's privacy policy.</p>
|
19
foodapp/Pages/Privacy.cshtml.cs
Normal file
19
foodapp/Pages/Privacy.cshtml.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace foodapp.Pages;
|
||||
|
||||
public class PrivacyModel : PageModel
|
||||
{
|
||||
private readonly ILogger<PrivacyModel> _logger;
|
||||
|
||||
public PrivacyModel(ILogger<PrivacyModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
51
foodapp/Pages/Shared/_Layout.cshtml
Normal file
51
foodapp/Pages/Shared/_Layout.cshtml
Normal file
@ -0,0 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - foodapp</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/foodapp.styles.css" asp-append-version="true" />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" asp-area="" asp-page="/Index">foodapp</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2024 - foodapp - <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
48
foodapp/Pages/Shared/_Layout.cshtml.css
Normal file
48
foodapp/Pages/Shared/_Layout.cshtml.css
Normal file
@ -0,0 +1,48 @@
|
||||
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
for details on configuring this project to bundle and minify static web assets. */
|
||||
|
||||
a.navbar-brand {
|
||||
white-space: normal;
|
||||
text-align: center;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #0077cc;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.border-top {
|
||||
border-top: 1px solid #e5e5e5;
|
||||
}
|
||||
.border-bottom {
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.box-shadow {
|
||||
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
|
||||
}
|
||||
|
||||
button.accept-policy {
|
||||
font-size: 1rem;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
line-height: 60px;
|
||||
}
|
2
foodapp/Pages/Shared/_ValidationScriptsPartial.cshtml
Normal file
2
foodapp/Pages/Shared/_ValidationScriptsPartial.cshtml
Normal file
@ -0,0 +1,2 @@
|
||||
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
|
||||
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
|
3
foodapp/Pages/_ViewImports.cshtml
Normal file
3
foodapp/Pages/_ViewImports.cshtml
Normal file
@ -0,0 +1,3 @@
|
||||
@using foodapp
|
||||
@namespace foodapp.Pages
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
3
foodapp/Pages/_ViewStart.cshtml
Normal file
3
foodapp/Pages/_ViewStart.cshtml
Normal file
@ -0,0 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
29
foodapp/Program.cs
Normal file
29
foodapp/Program.cs
Normal file
@ -0,0 +1,29 @@
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews(); // This registers MVC
|
||||
builder.Services.AddRazorPages();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Error");
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllerRoute( // Make sure this is before MapRazorPages()
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
app.MapRazorPages();
|
||||
|
||||
app.Run();
|
38
foodapp/Properties/launchSettings.json
Normal file
38
foodapp/Properties/launchSettings.json
Normal file
@ -0,0 +1,38 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:53579",
|
||||
"sslPort": 44347
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5279",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7224;http://localhost:5279",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
48
foodapp/README.MD
Normal file
48
foodapp/README.MD
Normal file
@ -0,0 +1,48 @@
|
||||
1 Setting Up the ASP.NET Core Web Application
|
||||
what you need
|
||||
Install .NET SDK.
|
||||
Install Visual Studio or Visual Studio Code.
|
||||
Install MySQL.
|
||||
Install Git.
|
||||
Create ASP.NET Core Project
|
||||
> dotnet new webapp -n FoodApp
|
||||
> cd FoodApp
|
||||
|
||||
FoodApp
|
||||
|
||||
FoodApp is an ASP.NET Core web application designed to facilitate online food ordering. It enables users to create, update, delete, and view food items, making it easier to manage food orders.
|
||||
|
||||
2 Description
|
||||
|
||||
This web application is built using ASP.NET Core and integrates with MySQL for data storage. The application is containerized using Docker, which simplifies deployment and environment consistency.
|
||||
|
||||
3 Features
|
||||
|
||||
- CRUD operations on food items.
|
||||
- Docker support for easy deployment.
|
||||
- Scaffolding for rapid page generation.
|
||||
- Entity Framework Core for database interactions.
|
||||
|
||||
4 Technical Details
|
||||
Frontend:
|
||||
HTML, CSS, and Razor syntax are used to create dynamic web pages.
|
||||
Bootstrap framework ensures a clean and responsive design.
|
||||
|
||||
Backend:
|
||||
ASP.NET Core MVC framework is used for server-side scripting.
|
||||
Entity Framework Core with Pomelo.EntityFrameworkCore.MySql is utilized for database operations.
|
||||
|
||||
de
|
||||
Deployment
|
||||
|
||||
Azure Container Instances (ACI):
|
||||
The application is deployed to Azure Container Instances (ACI), providing scalability and flexibility.
|
||||
Docker containers are used for packaging the application.
|
||||
|
||||
Database Setup:
|
||||
A MySQL database is hosted on Azure, storing food item information.
|
||||
Migration files are used to manage the database schema.
|
||||
|
||||
Public Access:
|
||||
The application is accessible via the provided url - foodiweb.azurewebsites.net.
|
||||
Users can interact with the application through their web browsers.
|
59
foodapp/Startup.cs
Normal file
59
foodapp/Startup.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using FoodApp.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FoodApp
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllersWithViews();
|
||||
|
||||
// Adding DbContext with MySQL configuration
|
||||
services.AddDbContext<ApplicationDbContext>(options =>
|
||||
options.UseMySql(Configuration.GetConnectionString("DefaultConnection"),
|
||||
new MySqlServerVersion(new Version(8, 0, 21))));
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
app.UseHsts();
|
||||
}
|
||||
// app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
24
foodapp/Views/FoodItems/Create.cshtml
Normal file
24
foodapp/Views/FoodItems/Create.cshtml
Normal file
@ -0,0 +1,24 @@
|
||||
@model FoodApp.Models.FoodItem
|
||||
|
||||
<h1>Add New Food Item</h1>
|
||||
|
||||
<form asp-action="Create">
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Name" class="control-label"></label>
|
||||
<input asp-for="Name" class="form-control" />
|
||||
<span asp-validation-for="Name" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Description" class="control-label"></label>
|
||||
<input asp-for="Description" class="form-control" />
|
||||
<span asp-validation-for="Description" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="submit" value="Create" class="btn btn-primary" />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div>
|
||||
<a asp-action="Index">Back to List</a>
|
||||
</div>
|
24
foodapp/Views/FoodItems/Index.cshtml
Normal file
24
foodapp/Views/FoodItems/Index.cshtml
Normal file
@ -0,0 +1,24 @@
|
||||
@model IEnumerable<FoodApp.Models.FoodItem>
|
||||
|
||||
<h1>Food Items</h1>
|
||||
|
||||
<p>
|
||||
<a asp-action="Create">Add New Item</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>@Html.DisplayFor(modelItem => item.Name)</td>
|
||||
<td>@Html.DisplayFor(modelItem => item.Description)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
14
foodapp/appsettings.Development.json
Normal file
14
foodapp/appsettings.Development.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"DetailedErrors": true,
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "server=localhost;database=foodapp;user=alchemist;password=Mum@2005!"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
13
foodapp/appsettings.json
Normal file
13
foodapp/appsettings.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "server=localhost;database=foodapp;user=alchemist;password=Mum@2005!"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
BIN
foodapp/bin/Debug/net8.0/Humanizer.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Humanizer.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.AspNetCore.Razor.Language.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.AspNetCore.Razor.Language.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.Bcl.AsyncInterfaces.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.Bcl.AsyncInterfaces.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.Build.Framework.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.Build.Framework.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.Build.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.Build.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.CSharp.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.CSharp.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.Elfie.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.Elfie.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.Features.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.Features.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.Razor.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.Razor.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.Scripting.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.Scripting.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.Workspaces.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.Workspaces.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.CodeAnalysis.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.DiaSymReader.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.DiaSymReader.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.DotNet.Scaffolding.Shared.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.DotNet.Scaffolding.Shared.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.EntityFrameworkCore.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.EntityFrameworkCore.dll
Normal file
Binary file not shown.
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.NET.StringTools.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.NET.StringTools.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Microsoft.Win32.SystemEvents.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Microsoft.Win32.SystemEvents.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Mono.TextTemplating.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Mono.TextTemplating.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/MySqlConnector.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/MySqlConnector.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Newtonsoft.Json.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Newtonsoft.Json.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/NuGet.Common.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/NuGet.Common.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/NuGet.Configuration.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/NuGet.Configuration.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/NuGet.DependencyResolver.Core.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/NuGet.DependencyResolver.Core.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/NuGet.Frameworks.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/NuGet.Frameworks.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/NuGet.LibraryModel.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/NuGet.LibraryModel.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/NuGet.Packaging.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/NuGet.Packaging.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/NuGet.ProjectModel.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/NuGet.ProjectModel.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/NuGet.Protocol.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/NuGet.Protocol.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/NuGet.Versioning.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/NuGet.Versioning.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/Pomelo.EntityFrameworkCore.MySql.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/Pomelo.EntityFrameworkCore.MySql.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/System.CodeDom.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/System.CodeDom.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/System.Composition.AttributedModel.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/System.Composition.AttributedModel.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/System.Composition.Convention.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/System.Composition.Convention.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/System.Composition.Hosting.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/System.Composition.Hosting.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/System.Composition.Runtime.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/System.Composition.Runtime.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/System.Composition.TypedParts.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/System.Composition.TypedParts.dll
Normal file
Binary file not shown.
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/System.Drawing.Common.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/System.Drawing.Common.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/System.Security.Permissions.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/System.Security.Permissions.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/System.Windows.Extensions.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/System.Windows.Extensions.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/af/Humanizer.resources.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/af/Humanizer.resources.dll
Normal file
Binary file not shown.
14
foodapp/bin/Debug/net8.0/appsettings.Development.json
Normal file
14
foodapp/bin/Debug/net8.0/appsettings.Development.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"DetailedErrors": true,
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "server=localhost;database=foodapp;user=alchemist;password=Mum@2005!"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
13
foodapp/bin/Debug/net8.0/appsettings.json
Normal file
13
foodapp/bin/Debug/net8.0/appsettings.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "server=localhost;database=foodapp;user=alchemist;password=Mum@2005!"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
BIN
foodapp/bin/Debug/net8.0/ar/Humanizer.resources.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/ar/Humanizer.resources.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/az/Humanizer.resources.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/az/Humanizer.resources.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/bg/Humanizer.resources.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/bg/Humanizer.resources.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/bn-BD/Humanizer.resources.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/bn-BD/Humanizer.resources.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/cs/Humanizer.resources.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/cs/Humanizer.resources.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/cs/Microsoft.CodeAnalysis.resources.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/cs/Microsoft.CodeAnalysis.resources.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/da/Humanizer.resources.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/da/Humanizer.resources.dll
Normal file
Binary file not shown.
BIN
foodapp/bin/Debug/net8.0/de/Humanizer.resources.dll
Normal file
BIN
foodapp/bin/Debug/net8.0/de/Humanizer.resources.dll
Normal file
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user