|
@@ -56,7 +56,12 @@ namespace GreenTree.Strohrmann.ERP.Web.Controllers
|
|
|
// GET: CustomerController/Details/5
|
|
// GET: CustomerController/Details/5
|
|
|
public ActionResult Details(int id)
|
|
public ActionResult Details(int id)
|
|
|
{
|
|
{
|
|
|
- return View();
|
|
|
|
|
|
|
+ var customer = _eRPDbContext.Customers
|
|
|
|
|
+ .FirstOrDefault(c => c.Id == id);
|
|
|
|
|
+
|
|
|
|
|
+ var customerModel = new CustomerModel(customer);
|
|
|
|
|
+
|
|
|
|
|
+ return View(customerModel);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// GET: CustomerController/Create
|
|
// GET: CustomerController/Create
|
|
@@ -68,43 +73,67 @@ namespace GreenTree.Strohrmann.ERP.Web.Controllers
|
|
|
// POST: CustomerController/Create
|
|
// POST: CustomerController/Create
|
|
|
[HttpPost]
|
|
[HttpPost]
|
|
|
[ValidateAntiForgeryToken]
|
|
[ValidateAntiForgeryToken]
|
|
|
- public ActionResult Create(IFormCollection collection)
|
|
|
|
|
|
|
+ public ActionResult Create(CustomerModel model)
|
|
|
{
|
|
{
|
|
|
- try
|
|
|
|
|
- {
|
|
|
|
|
- return RedirectToAction(nameof(Index));
|
|
|
|
|
- }
|
|
|
|
|
- catch
|
|
|
|
|
|
|
+ if (!ModelState.IsValid)
|
|
|
|
|
+ return View(model);
|
|
|
|
|
+
|
|
|
|
|
+ var customer = new Customer
|
|
|
{
|
|
{
|
|
|
- return View();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Firstname = model.Firstname,
|
|
|
|
|
+ Lastname = model.Lastname,
|
|
|
|
|
+ CompanyName = model.CompanyName,
|
|
|
|
|
+ Address = model.Address,
|
|
|
|
|
+ Town = model.Town,
|
|
|
|
|
+ ZipCode = model.ZipCode,
|
|
|
|
|
+ Country = model.Country,
|
|
|
|
|
+ IsBusiness = model.IsBusiness,
|
|
|
|
|
+ CreatedBy = User.Identity.Name,
|
|
|
|
|
+ CreatedOn = DateTime.Now
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ _eRPDbContext.Customers.Add(customer);
|
|
|
|
|
+ _eRPDbContext.SaveChanges();
|
|
|
|
|
+
|
|
|
|
|
+ return RedirectToAction(nameof(Index));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// GET: CustomerController/Edit/5
|
|
// GET: CustomerController/Edit/5
|
|
|
public ActionResult Edit(int id)
|
|
public ActionResult Edit(int id)
|
|
|
{
|
|
{
|
|
|
- return View();
|
|
|
|
|
|
|
+ var customer = _eRPDbContext.Customers
|
|
|
|
|
+ .FirstOrDefault(c => c.Id == id);
|
|
|
|
|
+
|
|
|
|
|
+ var customerModel = new CustomerModel(customer);
|
|
|
|
|
+
|
|
|
|
|
+ return View(customerModel);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// POST: CustomerController/Edit/5
|
|
// POST: CustomerController/Edit/5
|
|
|
[HttpPost]
|
|
[HttpPost]
|
|
|
[ValidateAntiForgeryToken]
|
|
[ValidateAntiForgeryToken]
|
|
|
- public ActionResult Edit(int id, IFormCollection collection)
|
|
|
|
|
- {
|
|
|
|
|
- try
|
|
|
|
|
- {
|
|
|
|
|
- return RedirectToAction(nameof(Index));
|
|
|
|
|
- }
|
|
|
|
|
- catch
|
|
|
|
|
- {
|
|
|
|
|
- return View();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // GET: CustomerController/Delete/5
|
|
|
|
|
- public ActionResult Delete(int id)
|
|
|
|
|
|
|
+ public ActionResult Edit(int id, CustomerModel model)
|
|
|
{
|
|
{
|
|
|
- return View();
|
|
|
|
|
|
|
+ if (!ModelState.IsValid)
|
|
|
|
|
+ return View(model);
|
|
|
|
|
+
|
|
|
|
|
+ var customer = _eRPDbContext.Customers
|
|
|
|
|
+ .FirstOrDefault(u => u.Id == id);
|
|
|
|
|
+
|
|
|
|
|
+ customer.Firstname = model.Firstname;
|
|
|
|
|
+ customer.Lastname = model.Lastname;
|
|
|
|
|
+ customer.CompanyName = model.CompanyName;
|
|
|
|
|
+ customer.Address = model.Address;
|
|
|
|
|
+ customer.Town = model.Town;
|
|
|
|
|
+ customer.ZipCode = model.ZipCode;
|
|
|
|
|
+ customer.Country = model.Country;
|
|
|
|
|
+ customer.IsBusiness = model.IsBusiness;
|
|
|
|
|
+ customer.ChangedBy = User.Identity.Name;
|
|
|
|
|
+ customer.ChangedOn = DateTime.Now;
|
|
|
|
|
+
|
|
|
|
|
+ _eRPDbContext.SaveChanges();
|
|
|
|
|
+
|
|
|
|
|
+ return RedirectToAction(nameof(Index));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// POST: CustomerController/Delete/5
|
|
// POST: CustomerController/Delete/5
|
|
@@ -112,14 +141,13 @@ namespace GreenTree.Strohrmann.ERP.Web.Controllers
|
|
|
[ValidateAntiForgeryToken]
|
|
[ValidateAntiForgeryToken]
|
|
|
public ActionResult Delete(int id, IFormCollection collection)
|
|
public ActionResult Delete(int id, IFormCollection collection)
|
|
|
{
|
|
{
|
|
|
- try
|
|
|
|
|
- {
|
|
|
|
|
- return RedirectToAction(nameof(Index));
|
|
|
|
|
- }
|
|
|
|
|
- catch
|
|
|
|
|
- {
|
|
|
|
|
- return View();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ var customer = _eRPDbContext.Customers
|
|
|
|
|
+ .FirstOrDefault(c => c.Id == id);
|
|
|
|
|
+
|
|
|
|
|
+ _eRPDbContext.Customers.Remove(customer);
|
|
|
|
|
+ _eRPDbContext.SaveChanges();
|
|
|
|
|
+
|
|
|
|
|
+ return RedirectToAction(nameof(Index));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
#endregion
|