Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Feature supplier #32

Merged
merged 17 commits into from
May 15, 2018
Merged
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
6 changes: 2 additions & 4 deletions src/AssetManager.Core/Entities/Supplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = " ")]
Expand All @@ -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; }

Expand All @@ -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; }

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class AssetManagerContext : DbContext
public AssetManagerContext( DbContextOptions<AssetManagerContext> options) : base(options) { }

DbSet<Company> Companies { get; set; }
DbSet<Supplier> Suppliers { get; set; }
}
}
10 changes: 6 additions & 4 deletions src/AssetManager.Infrastructure/Data/EfRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ public async Task DeleteAsync(T entity)
await _dbContext.SaveChangesAsync();
}

public Task<T> GetByIdAsync(int id)
public async Task<T> GetByIdAsync(int id)
{
throw new NotImplementedException();

return await _dbContext.Set<T>().SingleOrDefaultAsync(m => m.Id == id);
}

public async Task<List<T>> ListAllAsync()
{
return await _dbContext.Set<T>().ToListAsync();
}

public Task UpdateAsync(T entity)
public async Task UpdateAsync(T entity)
{
throw new NotImplementedException();
_dbContext.Entry(entity).State = EntityState.Modified;
await _dbContext.SaveChangesAsync();
}
}
}
77 changes: 59 additions & 18 deletions src/AssetManager.Web/Controllers/CompaniesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,33 @@ public class CompaniesController : Controller
public CompaniesController(IAsyncRepository<Company> repository)
{
this._companyRepository = repository;

}

// GET: Companies
[HttpGet]
public async Task<IActionResult> 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<IActionResult> 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));
Expand All @@ -58,19 +55,30 @@ public async Task<IActionResult> Create(Company company)
}

// GET: Companies/Edit/5
public ActionResult Edit(int id)
[HttpGet]
public async Task<IActionResult> 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<IActionResult> 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));
}
Expand All @@ -80,20 +88,53 @@ public ActionResult Edit(int id, IFormCollection collection)
}
}

// GET: Companies/Details/5
[HttpGet]
public async Task<IActionResult> 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<IActionResult> 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<IActionResult> DeleteConfirmed(int id, Company company)
{

try
{
// TODO: Add delete logic here

if (id == company.Id)
{
await _companyRepository.DeleteAsync(company);
}

return RedirectToAction(nameof(Index));
}
Expand Down
148 changes: 148 additions & 0 deletions src/AssetManager.Web/Controllers/SupplierController.cs
Original file line number Diff line number Diff line change
@@ -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<Supplier> _supplierRepository;
public SupplierController(IAsyncRepository<Supplier> repository)
{
_supplierRepository = repository;
}

// GET: Supplier
[HttpGet]
public async Task<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> DeleteConfirmed(int id, Supplier supplier)
{
try
{
if (id == supplier.Id)
{
await _supplierRepository.DeleteAsync(supplier);
}

return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
}
}
Loading