Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #1

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions SalesWebMVC.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31515.178
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SalesWebMVC", "SalesWebMVC\SalesWebMVC.csproj", "{9F3CCFCB-B62C-4382-A6F1-2065B9D4062E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9F3CCFCB-B62C-4382-A6F1-2065B9D4062E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F3CCFCB-B62C-4382-A6F1-2065B9D4062E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F3CCFCB-B62C-4382-A6F1-2065B9D4062E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F3CCFCB-B62C-4382-A6F1-2065B9D4062E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B94C0197-BFB4-42F7-BB20-74E076EC4790}
EndGlobalSection
EndGlobal
153 changes: 153 additions & 0 deletions SalesWebMVC/Controllers/DepartmentsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using SalesWebMVC.Data;
using SalesWebMVC.Models;

namespace SalesWebMVC.Controllers
{
public class DepartmentsController : Controller
{
private readonly SalesWebMVCContext _context;

public DepartmentsController(SalesWebMVCContext context)
{
_context = context;
}

// GET: Departments
public async Task<IActionResult> Index()
{
return View(await _context.Department.ToListAsync());
}

// GET: Departments/Details/5
public async Task<IActionResult> Details(int? id)
{
if (id == null)
{
return NotFound();
}

var department = await _context.Department
.FirstOrDefaultAsync(m => m.Id == id);
if (department == null)
{
return NotFound();
}

return View(department);
}

// GET: Departments/Create
public IActionResult Create()
{
return View();
}

// POST: Departments/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Name")] Department department)
{
if (ModelState.IsValid)
{
_context.Add(department);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(department);
}

// GET: Departments/Edit/5
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}

var department = await _context.Department.FindAsync(id);
if (department == null)
{
return NotFound();
}
return View(department);
}

// POST: Departments/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, [Bind("Id,Name")] Department department)
{
if (id != department.Id)
{
return NotFound();
}

if (ModelState.IsValid)
{
try
{
_context.Update(department);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!DepartmentExists(department.Id))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
return View(department);
}

// GET: Departments/Delete/5
public async Task<IActionResult> Delete(int? id)
{
if (id == null)
{
return NotFound();
}

var department = await _context.Department
.FirstOrDefaultAsync(m => m.Id == id);
if (department == null)
{
return NotFound();
}

return View(department);
}

// POST: Departments/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
var department = await _context.Department.FindAsync(id);
_context.Department.Remove(department);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}

private bool DepartmentExists(int id)
{
return _context.Department.Any(e => e.Id == id);
}
}
}
46 changes: 46 additions & 0 deletions SalesWebMVC/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Microsoft.AspNetCore.Mvc;
using SalesWebMVC.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using SalesWebMVC.Models.ViewModels;

namespace SalesWebMVC.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}

public IActionResult About()
{
ViewData["Message"] = "Salles Web MVC App from C# Course.";
ViewData["email"] = "rafelgs20@outlook.";


return View();
}

public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";

return View();
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
20 changes: 20 additions & 0 deletions SalesWebMVC/Data/SalesWebMVCContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using SalesWebMVC.Models;

namespace SalesWebMVC.Data
{
public class SalesWebMVCContext : DbContext
{
public SalesWebMVCContext (DbContextOptions<SalesWebMVCContext> options)
: base(options)
{

}

public DbSet<SalesWebMVC.Models.Department> Department { get; set; }
}
}
36 changes: 36 additions & 0 deletions SalesWebMVC/Data/SeedingService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SalesWebMVC.Models;

namespace SalesWebMVC.Data
{
public class SeedingService
{
private SalesWebMVCContext _context;

public SeedingService(SalesWebMVCContext context)
{
_context = context;
}
public void Seed()
{
//if (_context.Department.Any() ||
// _context.Seller.Any() ||
// _context.SalesRecord.Any())
//{
// return;
//}
//Department d1 = new Department(1, "Computers");
//Department d2 = new Department(2, "Eletronics");
//Department d3 = new Department(3, "Fashion");
//Department d4 = new Department(4, "Books");



}


}
}
35 changes: 35 additions & 0 deletions SalesWebMVC/Migrations/20210817124002_Initial.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions SalesWebMVC/Migrations/20210817124002_Initial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace SalesWebMVC.Migrations
{
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Department",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Department", x => x.Id);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Department");
}
}
}
33 changes: 33 additions & 0 deletions SalesWebMVC/Migrations/SalesWebMVCContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SalesWebMVC.Data;

namespace SalesWebMVC.Migrations
{
[DbContext(typeof(SalesWebMVCContext))]
partial class SalesWebMVCContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.1.14-servicing-32113")
.HasAnnotation("Relational:MaxIdentifierLength", 64);

modelBuilder.Entity("SalesWebMVC.Models.Department", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();

b.Property<string>("Name");

b.HasKey("Id");

b.ToTable("Department");
});
#pragma warning restore 612, 618
}
}
}
Loading