Skip to content

Commit

Permalink
Auto-save-commit-1/29/2024--1:11:14-PM
Browse files Browse the repository at this point in the history
  • Loading branch information
neojarvis committed Jan 29, 2024
1 parent 9a98c5f commit c3ca6c1
Show file tree
Hide file tree
Showing 1,203 changed files with 133,103 additions and 12,148 deletions.
143 changes: 143 additions & 0 deletions dotnetapp/Controllers/DealerController.cs
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));
}


}
15 changes: 15 additions & 0 deletions dotnetapp/Models/ApplicationDbContext.cs
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; }

}
}
19 changes: 19 additions & 0 deletions dotnetapp/Models/Dealer.cs
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; }
}
}
8 changes: 8 additions & 0 deletions dotnetapp/Models/ErrorViewModel.cs
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);
}
31 changes: 31 additions & 0 deletions dotnetapp/Program.cs
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();
28 changes: 28 additions & 0 deletions dotnetapp/Properties/launchSettings.json
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"
}
}
}
}
1 change: 1 addition & 0 deletions dotnetapp/TestProject/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using NUnit.Framework;
24 changes: 24 additions & 0 deletions dotnetapp/TestProject/TestProject.csproj
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>
Loading

0 comments on commit c3ca6c1

Please sign in to comment.