-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto-save-commit-1/29/2024--1:11:14-PM
- Loading branch information
Showing
1,203 changed files
with
133,103 additions
and
12,148 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using dotnetapp.Models; | ||
namespace dotnetapp.Controllers; | ||
public class DealerController : Controller | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public DealerController(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
// GET: Dealer | ||
public IActionResult Index() | ||
{ | ||
var dealers = _context.Dealers.ToList(); | ||
return View(dealers); | ||
} | ||
|
||
// GET: Dealer/Details/5 | ||
public IActionResult Details(int? id) | ||
{ | ||
if (id == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
var dealer = _context.Dealers | ||
.FirstOrDefault(e => e.ID == id); | ||
|
||
if (dealer == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return View(dealer); | ||
} | ||
|
||
// GET: Dealer/Create | ||
public IActionResult Create() | ||
{ | ||
ViewBag.Dealers = _context.Dealers.ToList(); | ||
return View(); | ||
} | ||
|
||
// POST: Dealer/Create | ||
[HttpPost] | ||
public IActionResult Create(Dealer dealer) | ||
{ | ||
try | ||
{ | ||
_context.Dealers.Add(dealer); | ||
_context.SaveChanges(); | ||
return RedirectToAction("Index"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
// Log the exception for debugging purposes | ||
Console.WriteLine(ex.Message); | ||
return View(dealer); // You can also redirect to an error page | ||
} | ||
} | ||
|
||
// GET: Dealer/Edit/5 | ||
public IActionResult Edit(int? id) | ||
{ | ||
if (id == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
var dealer = _context.Dealers.Find(id); | ||
|
||
if (dealer == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
ViewBag.Dealers = _context.Dealers.ToList(); | ||
return View(dealer); | ||
} | ||
|
||
// POST: Dealer/Edit/5 | ||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public IActionResult Edit(int id, Dealer dealer) | ||
{ | ||
if (id != dealer.ID) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
// if (ModelState.IsValid) | ||
{ | ||
_context.Dealers.Update(dealer); | ||
_context.SaveChanges(); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
|
||
ViewBag.Dealers = _context.Dealers.ToList(); | ||
return View(dealer); | ||
} | ||
|
||
// GET: Dealer/Delete/5 | ||
// [HttpPost, ActionName("Delete")] | ||
// public IActionResult Delete(int? id) | ||
// { | ||
// if (id == null) | ||
// { | ||
// return NotFound(); | ||
// } | ||
|
||
// var dealer = _context.Dealers | ||
// .FirstOrDefault(e => e.ID == id); | ||
|
||
// if (dealer == null) | ||
// { | ||
// return NotFound(); | ||
// } | ||
|
||
// return View(dealer); | ||
// } | ||
|
||
[HttpPost, ActionName("Delete")] | ||
|
||
public IActionResult Delete(int id) | ||
{ | ||
var Dealer = _context.Dealers.Find(id); | ||
|
||
if (Dealer == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
_context.Dealers.Remove(Dealer); | ||
_context.SaveChanges(); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
|
||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace dotnetapp.Models | ||
{ | ||
|
||
public class ApplicationDbContext : DbContext | ||
{ | ||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) | ||
{ | ||
} | ||
|
||
public DbSet<Dealer> Dealers { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.ComponentModel.DataAnnotations; | ||
namespace dotnetapp.Models | ||
{ | ||
public class Dealer | ||
{ | ||
public int ID { get; set; } | ||
public string Name { get; set; } | ||
public DateTime RegistrationDate {get; set;} | ||
public string AutoPartName { get; set; } | ||
public string Manufacturer { get; set; } | ||
public string MobileNumber { get; set; } | ||
public string Email { get; set; } | ||
public string Description { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace dotnetapp.Models; | ||
|
||
public class ErrorViewModel | ||
{ | ||
public string? RequestId { get; set; } | ||
|
||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using dotnetapp.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
builder.Services.AddControllersWithViews(); | ||
builder.Services.AddDbContext<ApplicationDbContext>(options => | ||
options.UseSqlServer(builder.Configuration.GetConnectionString("DevConnection"))); | ||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (!app.Environment.IsDevelopment()) | ||
{ | ||
app.UseExceptionHandler("/Home/Error"); | ||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. | ||
app.UseHsts(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
app.UseStaticFiles(); | ||
|
||
app.UseRouting(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllerRoute( | ||
name: "default", | ||
pattern: "{controller=Dealer}/{action=Index}/{id?}"); | ||
|
||
app.Run(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:55666", | ||
"sslPort": 44372 | ||
} | ||
}, | ||
"profiles": { | ||
"BookStoreApp": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:7243;http://localhost:5202", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using NUnit.Framework; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" /> | ||
<PackageReference Include="NUnit" Version="3.13.3" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" /> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\dotnetapp.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.