diff --git a/src/AssetManager.Core/Entities/Supplier.cs b/src/AssetManager.Core/Entities/Supplier.cs index 8e6bac3..82b1bb3 100644 --- a/src/AssetManager.Core/Entities/Supplier.cs +++ b/src/AssetManager.Core/Entities/Supplier.cs @@ -15,7 +15,7 @@ public class Supplier: Entity [Display(Name ="Name")] public string Name { get; set; } - [Display(Name = "Name")] + [Display(Name = "Address")] public string Address { get; set; } [Display(Name = " ")] @@ -42,11 +42,9 @@ public class Supplier: Entity [Display(Name = "Contact")] public string Contact { get; set; } - [Display(Name = "Note")] public string Notes { get; set; } - [Display(Name = "Zip")] public string Zip { get; set; } @@ -55,9 +53,9 @@ public class Supplier: Entity [Display(Name = "Image")] public string Image { get; set; } + public DateTime CreateAt { get; set; } public DateTime UpdatedAt { get; set; } - public int UserId { get; set; } public DateTime DeletedAt { get; set; } } diff --git a/src/AssetManager.Infrastructure/Data/AssetManagerContext.cs b/src/AssetManager.Infrastructure/Data/AssetManagerContext.cs index c4921cf..916f9e1 100644 --- a/src/AssetManager.Infrastructure/Data/AssetManagerContext.cs +++ b/src/AssetManager.Infrastructure/Data/AssetManagerContext.cs @@ -11,5 +11,6 @@ public class AssetManagerContext : DbContext public AssetManagerContext( DbContextOptions options) : base(options) { } DbSet Companies { get; set; } + DbSet Suppliers { get; set; } } } diff --git a/src/AssetManager.Infrastructure/Data/EfRepository.cs b/src/AssetManager.Infrastructure/Data/EfRepository.cs index 898231f..90b3da5 100644 --- a/src/AssetManager.Infrastructure/Data/EfRepository.cs +++ b/src/AssetManager.Infrastructure/Data/EfRepository.cs @@ -30,9 +30,10 @@ public async Task DeleteAsync(T entity) await _dbContext.SaveChangesAsync(); } - public Task GetByIdAsync(int id) + public async Task GetByIdAsync(int id) { - throw new NotImplementedException(); + + return await _dbContext.Set().SingleOrDefaultAsync(m => m.Id == id); } public async Task> ListAllAsync() @@ -40,9 +41,10 @@ public async Task> ListAllAsync() return await _dbContext.Set().ToListAsync(); } - public Task UpdateAsync(T entity) + public async Task UpdateAsync(T entity) { - throw new NotImplementedException(); + _dbContext.Entry(entity).State = EntityState.Modified; + await _dbContext.SaveChangesAsync(); } } } diff --git a/src/AssetManager.Web/Controllers/CompaniesController.cs b/src/AssetManager.Web/Controllers/CompaniesController.cs index 08337e1..7fe2687 100644 --- a/src/AssetManager.Web/Controllers/CompaniesController.cs +++ b/src/AssetManager.Web/Controllers/CompaniesController.cs @@ -17,36 +17,33 @@ public class CompaniesController : Controller public CompaniesController(IAsyncRepository repository) { this._companyRepository = repository; + } // GET: Companies + [HttpGet] public async Task Index() { var companies = await _companyRepository.ListAllAsync(); return View(companies); } - // GET: Companies/Details/5 - public ActionResult Details(int id) - { - return View(); - } // GET: Companies/Create - public ActionResult Create() + [HttpGet] + public IActionResult Create() { return View(); } // POST: Companies/Create [HttpPost] - [ValidateAntiForgeryToken] public async Task Create(Company company) { try { - // TODO: Add insert logic here - + company.CreateDate = DateTime.Now; + company.UpdateDate = DateTime.Now; await _companyRepository.AddAsync(company); return RedirectToAction(nameof(Index)); @@ -58,19 +55,30 @@ public async Task Create(Company company) } // GET: Companies/Edit/5 - public ActionResult Edit(int id) + [HttpGet] + public async Task Edit(int id) { - return View(); + + var company = await _companyRepository.GetByIdAsync(id); + if (company == null) + { + return RedirectToAction(nameof(Index)); + } + return View(company); } // POST: Companies/Edit/5 [HttpPost] [ValidateAntiForgeryToken] - public ActionResult Edit(int id, IFormCollection collection) + public async Task Edit(int id, Company company) { try { - // TODO: Add update logic here + if (id == company.Id) + { + company.UpdateDate = DateTime.Now; + await _companyRepository.UpdateAsync(company); + } return RedirectToAction(nameof(Index)); } @@ -80,20 +88,53 @@ public ActionResult Edit(int id, IFormCollection collection) } } + // GET: Companies/Details/5 + [HttpGet] + public async Task Details(int id = 0) + { + if (id >= 0) + { + return RedirectToAction(nameof(Index)); + } + + var company = await _companyRepository.GetByIdAsync(id); + if (company == null) + { + return RedirectToAction(nameof(Index)); + } + return View(company); + } + // GET: Companies/Delete/5 - public ActionResult Delete(int id) + [HttpGet] + public async Task Delete(int id = 0) { - return View(); + if (id >= 0) + { + return RedirectToAction(nameof(Index)); + } + + var company = await _companyRepository.GetByIdAsync(id); + if (company == null) + { + return RedirectToAction(nameof(Index)); + } + return View(company); } // POST: Companies/Delete/5 - [HttpPost] + [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] - public ActionResult Delete(int id, IFormCollection collection) + public async Task DeleteConfirmed(int id, Company company) { + try { - // TODO: Add delete logic here + + if (id == company.Id) + { + await _companyRepository.DeleteAsync(company); + } return RedirectToAction(nameof(Index)); } diff --git a/src/AssetManager.Web/Controllers/SupplierController.cs b/src/AssetManager.Web/Controllers/SupplierController.cs new file mode 100644 index 0000000..f5d008e --- /dev/null +++ b/src/AssetManager.Web/Controllers/SupplierController.cs @@ -0,0 +1,148 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using AssetManager.Core.Entities; +using AssetManager.Core.Interfaces; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace AssetManager.Web.Controllers +{ + public class SupplierController : Controller + { + private readonly IAsyncRepository _supplierRepository; + public SupplierController(IAsyncRepository repository) + { + _supplierRepository = repository; + } + + // GET: Supplier + [HttpGet] + public async Task Index() + { + var companies = await _supplierRepository.ListAllAsync(); + return View(companies); + } + + + + // GET: Supplier/Create + [HttpGet] + public IActionResult Create() + { + return View(); + + } + + // POST: Supplier/Create + [HttpPost, ActionName("Create")] + [ValidateAntiForgeryToken] + public async Task Insert(Supplier Supplier) + { + if(Supplier == null) + { + return RedirectToAction(nameof(Create)); + } + try + { + + await _supplierRepository.AddAsync(Supplier); + + return RedirectToAction(nameof(Index)); + } + catch + { + return View(); + } + } + + // GET: Supplier/Edit/5 + [HttpGet] + public async Task Edit(int id = 0) + { + if (id >= 0) + { + return RedirectToAction(nameof(Index)); + } + + var supplier = await _supplierRepository.GetByIdAsync(id); + if(supplier == null) + { + return NotFound(); + } + return View(supplier); + } + + // POST: Supplier/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(int id, Supplier supplier) + { + try + { + if (id == supplier.Id) + { + supplier.UpdatedAt = DateTime.Now; + await _supplierRepository.UpdateAsync(supplier); + } + + return RedirectToAction(nameof(Index)); + } + catch + { + return View(); + } + } + + [HttpGet] + public async Task Details(int id=0) + { + if (id >= 0) + { + return RedirectToAction(nameof(Index)); + } + var supplier = await _supplierRepository.GetByIdAsync(id); + if (supplier == null) + { + return RedirectToAction(nameof(Index)); + } + return View(supplier); + } + + // GET: Supplier/Delete/5 + public async Task Delete(int id=0) + { + if (id >= 0) + { + return RedirectToAction(nameof(Index)); + } + var supplier = await _supplierRepository.GetByIdAsync(id); + if (supplier == null) + { + return RedirectToAction(nameof(Index)); + } + return View(supplier); + } + + // POST: Supplier/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id, Supplier supplier) + { + try + { + if (id == supplier.Id) + { + await _supplierRepository.DeleteAsync(supplier); + } + + return RedirectToAction(nameof(Index)); + } + catch + { + return View(); + } + } + } +} \ No newline at end of file diff --git a/src/AssetManager.Web/Views/Companies/Create.cshtml b/src/AssetManager.Web/Views/Companies/Create.cshtml index 68435fa..bd1407c 100644 --- a/src/AssetManager.Web/Views/Companies/Create.cshtml +++ b/src/AssetManager.Web/Views/Companies/Create.cshtml @@ -4,50 +4,54 @@ ViewData["Title"] = "Create"; } -

Create

- -

Company

+

Create Company


-
-
-
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- + +
+
+
+
- +
+
+ + +
+ +
+ +
+ + +
+
+ +
+ +
+ + +
+
+ + +
+
+
+ +
+
+
+
+
- + @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} } diff --git a/src/AssetManager.Web/Views/Companies/Delete.cshtml b/src/AssetManager.Web/Views/Companies/Delete.cshtml new file mode 100644 index 0000000..a228c6d --- /dev/null +++ b/src/AssetManager.Web/Views/Companies/Delete.cshtml @@ -0,0 +1,50 @@ +@model AssetManager.Core.Entities.Company + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

Company

+
+
+
+ @Html.DisplayNameFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Name) +
+
+ @Html.DisplayNameFor(model => model.CreateDate) +
+
+ @Html.DisplayFor(model => model.CreateDate) +
+
+ @Html.DisplayNameFor(model => model.UpdateDate) +
+
+ @Html.DisplayFor(model => model.UpdateDate) +
+
+ @Html.DisplayNameFor(model => model.ImageUrl) +
+
+ @Html.DisplayFor(model => model.ImageUrl) +
+
+ @Html.DisplayNameFor(model => model.Id) +
+
+ @Html.DisplayFor(model => model.Id) +
+
+ +
+ | + Back to List +
+
diff --git a/src/AssetManager.Web/Views/Companies/Details.cshtml b/src/AssetManager.Web/Views/Companies/Details.cshtml new file mode 100644 index 0000000..d993a92 --- /dev/null +++ b/src/AssetManager.Web/Views/Companies/Details.cshtml @@ -0,0 +1,48 @@ +@model AssetManager.Core.Entities.Company + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

Company

+
+
+
+ @Html.DisplayNameFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Name) +
+
+ @Html.DisplayNameFor(model => model.CreateDate) +
+
+ @Html.DisplayFor(model => model.CreateDate) +
+
+ @Html.DisplayNameFor(model => model.UpdateDate) +
+
+ @Html.DisplayFor(model => model.UpdateDate) +
+
+ @Html.DisplayNameFor(model => model.ImageUrl) +
+
+ @Html.DisplayFor(model => model.ImageUrl) +
+
+ @Html.DisplayNameFor(model => model.Id) +
+
+ @Html.DisplayFor(model => model.Id) +
+
+
+
+ @Html.ActionLink("Edit", "Edit", new { id = Model.Id }) | + Back to List +
diff --git a/src/AssetManager.Web/Views/Companies/Edit.cshtml b/src/AssetManager.Web/Views/Companies/Edit.cshtml new file mode 100644 index 0000000..7e542b0 --- /dev/null +++ b/src/AssetManager.Web/Views/Companies/Edit.cshtml @@ -0,0 +1,55 @@ +@model AssetManager.Core.Entities.Company + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

Company

+
+
+ +
+
+
+ +
+
+
+ +
+ +
+ + +
+
+ +
+ +
+ + +
+
+ + +
+
+
+ +
+
+ +
+
+
+
+ + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} diff --git a/src/AssetManager.Web/Views/Companies/Index.cshtml b/src/AssetManager.Web/Views/Companies/Index.cshtml index d740177..4453cfd 100644 --- a/src/AssetManager.Web/Views/Companies/Index.cshtml +++ b/src/AssetManager.Web/Views/Companies/Index.cshtml @@ -7,53 +7,46 @@

Index

- Create New + Create New

- - - - - - - - - - - - -@foreach (var item in Model) { - - - - - - - - -} - -
- @Html.DisplayNameFor(model => model.Name) - - @Html.DisplayNameFor(model => model.CreateDate) - - @Html.DisplayNameFor(model => model.UpdateDate) - - @Html.DisplayNameFor(model => model.ImageUrl) - - @Html.DisplayNameFor(model => model.Id) -
- @Html.DisplayFor(modelItem => item.Name) - - @Html.DisplayFor(modelItem => item.CreateDate) - - @Html.DisplayFor(modelItem => item.UpdateDate) - - @Html.DisplayFor(modelItem => item.ImageUrl) - - @Html.DisplayFor(modelItem => item.Id) - - @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | - @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) | - @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) -
+
+
+
+ +
+
+
+ + + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Name) + + @Html.DisplayNameFor(model => model.ImageUrl) + Action
+ @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.ImageUrl) + + @Html.ActionLink("Edit", "Edit", new { id = item.Id }) | + @Html.ActionLink("Details", "Details", new { id=item.Id }) | + @Html.ActionLink("Delete", "Delete", new { id = item.Id }) +
+
+
diff --git a/src/AssetManager.Web/Views/Shared/_Layout.cshtml b/src/AssetManager.Web/Views/Shared/_Layout.cshtml index 0caa51f..4193637 100644 --- a/src/AssetManager.Web/Views/Shared/_Layout.cshtml +++ b/src/AssetManager.Web/Views/Shared/_Layout.cshtml @@ -10,6 +10,16 @@ + + + + + + + + +