| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http;
- using System.Threading.Tasks;
- using GreenTree.Strohrmann.ERP.Core.Domain.Business;
- using GreenTree.Strohrmann.ERP.Core.Helper;
- using GreenTree.Strohrmann.ERP.Domain.Model;
- using GreenTree.Strohrmann.ERP.Services.Geolocator;
- using GreenTree.Strohrmann.ERP.Web.Models.Business;
- using GreenTree.Strohrmann.ERP.Web.Models.Rights.User;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- namespace GreenTree.Strohrmann.ERP.Web.Controllers
- {
- public class SupplierController : Controller
- {
- #region DI fields
- // The global DbContext
- private readonly ERPDbContext _eRPDbContext;
- #endregion
- #region Ctor
- /// <summary>
- /// Initializes a new instance of the SupplierController class
- /// </summary>
- /// <param name="eRPDbContext">Global DbContext.</param>
- public SupplierController(ERPDbContext eRPDbContext)
- {
- _eRPDbContext = eRPDbContext;
- }
- #endregion
- #region Actions
- // GET: SupplierController
- public ActionResult Index()
- {
- var suppliers = _eRPDbContext.Suppliers
- .ToList()
- .Select(c => new SupplierModel(c));
- return View(suppliers);
- }
- // GET: SupplierController/Details/5
- public ActionResult Details(int id)
- {
- var supplier = _eRPDbContext.Suppliers
- .FirstOrDefault(c => c.Id == id);
- var supplierModel = new SupplierModel(supplier);
- return View(supplierModel);
- }
- // GET: SupplierController/Create
- public ActionResult Create()
- {
- return View();
- }
- // POST: SupplierController/Create
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Create(SupplierModel model)
- {
- if (!ModelState.IsValid)
- return View(model);
- var supplier = new Supplier
- {
- Name = model.Name,
- Description = model.Description,
- Address = model.Address,
- Town = model.Town,
- ZipCode = model.ZipCode,
- Country = model.Country,
- PhoneFirst = model.PhoneFirst,
- PhoneSecond = model.PhoneSecond,
- MailFirst = model.MailFirst,
- MailSecond = model.MailSecond,
- Comment = model.Comment,
- CreatedBy = User.Identity.Name,
- CreatedOn = DateTime.Now
- };
- _eRPDbContext.Suppliers.Add(supplier);
- _eRPDbContext.SaveChanges();
- return RedirectToAction(nameof(Index));
- }
- // GET: SupplierController/Edit/5
- public ActionResult Edit(int id)
- {
- var supplier = _eRPDbContext.Suppliers
- .FirstOrDefault(c => c.Id == id);
- var supplierModel = new SupplierModel(supplier);
- return View(supplierModel);
- }
- // POST: SupplierController/Edit/5
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Edit(int id, SupplierModel model)
- {
- if (!ModelState.IsValid)
- return View(model);
- var supplier = _eRPDbContext.Suppliers
- .FirstOrDefault(u => u.Id == id);
- supplier.Name = model.Name;
- supplier.Description = model.Description;
- supplier.Address = model.Address;
- supplier.Town = model.Town;
- supplier.ZipCode = model.ZipCode;
- supplier.Country = model.Country;
- supplier.PhoneFirst = model.PhoneFirst;
- supplier.PhoneSecond = model.PhoneSecond;
- supplier.MailFirst = model.MailFirst;
- supplier.MailSecond = model.MailSecond;
- supplier.Comment = model.Comment;
- supplier.ChangedBy = User.Identity.Name;
- supplier.ChangedOn = DateTime.Now;
- _eRPDbContext.SaveChanges();
- return RedirectToAction(nameof(Index));
- }
- // POST: SupplierController/Delete/5
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Delete(int id, IFormCollection collection)
- {
- var supplier = _eRPDbContext.Suppliers
- .FirstOrDefault(c => c.Id == id);
- _eRPDbContext.Suppliers.Remove(supplier);
- _eRPDbContext.SaveChanges();
- return RedirectToAction(nameof(Index));
- }
- #endregion
- }
- }
|