Explorar o código

Kundenbearbeitung fast abgeschlossen

Arne Diekmann %!s(int64=5) %!d(string=hai) anos
pai
achega
c0de7c4c89

+ 61 - 33
GreenTree.Strohrmann.ERP.Web/Controllers/CustomerController.cs

@@ -56,7 +56,12 @@ namespace GreenTree.Strohrmann.ERP.Web.Controllers
         // GET: CustomerController/Details/5
         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
@@ -68,43 +73,67 @@ namespace GreenTree.Strohrmann.ERP.Web.Controllers
         // POST: CustomerController/Create
         [HttpPost]
         [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
         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
         [HttpPost]
         [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
@@ -112,14 +141,13 @@ namespace GreenTree.Strohrmann.ERP.Web.Controllers
         [ValidateAntiForgeryToken]
         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

+ 3 - 2
GreenTree.Strohrmann.ERP.Web/Extension/HtmlContentExtension.cs

@@ -205,12 +205,13 @@ namespace GreenTree.Strohrmann.ERP.Web.Extension
                 : memberInfo.Name;
 
             var selectBuilder = new StringBuilder();
-            selectBuilder.AppendFormat("<select id=\"{0}\" name =\"{0}\">", name);
+            selectBuilder.AppendFormat("<select id=\"{0}\" name =\"{0}\" {1}>", name, String.Join(" ", htmlAttributes));
 
             var countries = CultureInfo.GetCultures(CultureTypes.AllCultures)
                 .Where(c => c.LCID != CultureInfo.InvariantCulture.LCID && !c.IsNeutralCulture)
                 .Select(c => new RegionInfo(c.LCID))
-                .Distinct();
+                .Distinct()
+                .OrderBy(r => r.DisplayName);
 
             foreach (var country in countries)
             {

+ 5 - 2
GreenTree.Strohrmann.ERP.Web/Models/Business/CustomerModel.cs

@@ -1,4 +1,6 @@
-using System;
+using GreenTree.Strohrmann.ERP.Core.Domain.Rights;
+using GreenTree.Strohrmann.ERP.Web.Models.Shared;
+using System;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
 using System.Linq;
@@ -6,7 +8,7 @@ using System.Threading.Tasks;
 
 namespace GreenTree.Strohrmann.ERP.Web.Models.Business
 {
-    public class CustomerModel
+    public class CustomerModel : TrackingModel
     {
         #region Properties
 
@@ -90,6 +92,7 @@ namespace GreenTree.Strohrmann.ERP.Web.Models.Business
         /// </summary>
         /// <param name="customer">Base customer entity.</param>
         public CustomerModel(Core.Domain.Business.Customer customer)
+            : base(customer)
         {
             if (customer == null) return;
 

+ 2 - 1
GreenTree.Strohrmann.ERP.Web/Models/Rights/User/UserModel.cs

@@ -1,4 +1,5 @@
-using System;
+using GreenTree.Strohrmann.ERP.Web.Models.Shared;
+using System;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
 using System.Linq;

+ 65 - 0
GreenTree.Strohrmann.ERP.Web/Models/Shared/TrackingModel.cs

@@ -0,0 +1,65 @@
+using GreenTree.Strohrmann.ERP.Core.Domain.Shared;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace GreenTree.Strohrmann.ERP.Web.Models.Shared
+{
+    public class TrackingModel
+    {
+        #region Properties
+
+        /// <summary>
+        /// Tracked creation user
+        /// </summary>
+        [Display(Name = "Erstellt von")]
+        public string CreatedBy { get; set; }
+
+        /// <summary>
+        /// Tracked creation datetime
+        /// </summary>
+        [Display(Name = "Erstellt am")]
+        [DisplayFormat(DataFormatString = "{0:dd.MM.yyyy - HH:mm \"Uhr\"}")]
+        public DateTime CreatedOn { get; set; }
+
+        /// <summary>
+        /// Tracked changed user
+        /// </summary>
+        [Display(Name = "Geändert von")]
+        public string ChangedBy { get; set; }
+
+        /// <summary>
+        /// Tracked changed datetime
+        /// </summary>
+        [Display(Name = "Geändert am")]
+        [DisplayFormat(DataFormatString = "{0:dd.MM.yyyy - HH:mm \"Uhr\"}")]
+        public DateTime? ChangedOn { get; set; }
+
+        #endregion
+
+        #region Ctor
+
+        /// <summary>
+        /// Initializes a new instance of the TrackModel class
+        /// </summary>
+        public TrackingModel() { }
+
+        /// <summary>
+        /// Initializes a new instance of the TrackModel class
+        /// </summary>
+        /// <param name="trackedEntity">The based tracked entity.</param>
+        public TrackingModel(TrackedEntity trackedEntity)
+        {
+            if (trackedEntity == null) return;
+
+            CreatedBy = trackedEntity.CreatedBy;
+            CreatedOn = trackedEntity.CreatedOn;
+            ChangedBy = trackedEntity.ChangedBy;
+            ChangedOn = trackedEntity.ChangedOn;
+        }
+
+        #endregion
+    }
+}

+ 1 - 7
GreenTree.Strohrmann.ERP.Web/Views/Customer/Create.cshtml

@@ -76,9 +76,6 @@
             </div>
         </div>
     </div>
-    <div class="card-deck mt-3">
-
-    </div>
 
     <hr />
 
@@ -88,7 +85,4 @@
             <a asp-action="Index">Zurück zur Liste</a>
         </div>
     </div>
-</form>
-
-
-
+</form>

+ 153 - 0
GreenTree.Strohrmann.ERP.Web/Views/Customer/Details.cshtml

@@ -0,0 +1,153 @@
+@model GreenTree.Strohrmann.ERP.Web.Models.Business.CustomerModel
+
+@{
+    ViewData["Title"] = "Kundendetails";
+}
+
+<h1>Kundendetails</h1>
+
+<h4>@Model.Lastname, @Model.Firstname</h4>
+
+<hr />
+
+<div class="card-deck">
+    <div class="card">
+        <div class="card-header pb-1">
+            <h6>Kundenname / -firma</h6>
+        </div>
+        <div class="card-body">
+            <dl class="row">
+                <dt class = "col-sm-6">
+                    @Html.DisplayNameFor(model => model.Id)
+                </dt>
+                <dd class = "col-sm-6">
+                    @Html.DisplayFor(model => model.Id)
+                </dd>
+                <dt class = "col-sm-6">
+                    @Html.DisplayNameFor(model => model.Firstname)
+                </dt>
+                <dd class = "col-sm-6">
+                    @Html.DisplayFor(model => model.Firstname)
+                </dd>
+                <dt class = "col-sm-6">
+                    @Html.DisplayNameFor(model => model.Lastname)
+                </dt>
+                <dd class = "col-sm-6">
+                    @Html.DisplayFor(model => model.Lastname)
+                </dd>
+                <dt class = "col-sm-6">
+                    @Html.DisplayNameFor(model => model.CompanyName)
+                </dt>
+                <dd class = "col-sm-6">
+                    @Html.DisplayFor(model => model.CompanyName)
+                </dd>
+            </dl>
+        </div>
+    </div>
+    <div class="card">
+        <div class="card-header pb-1">
+            <h6>Adressdaten</h6>
+        </div>
+        <div class="card-body">
+            <dl class="row">
+                <dt class = "col-sm-6">
+                    @Html.DisplayNameFor(model => model.Address)
+                </dt>
+                <dd class = "col-sm-6">
+                    @Html.DisplayFor(model => model.Address)
+                </dd>
+                <dt class = "col-sm-6">
+                    @Html.DisplayNameFor(model => model.Town)
+                </dt>
+                <dd class = "col-sm-6">
+                    @Html.DisplayFor(model => model.Town)
+                </dd>
+                <dt class = "col-sm-6">
+                    @Html.DisplayNameFor(model => model.ZipCode)
+                </dt>
+                <dd class = "col-sm-6">
+                    @Html.DisplayFor(model => model.ZipCode)
+                </dd>
+                <dt class = "col-sm-6">
+                    @Html.DisplayNameFor(model => model.Country)
+                </dt>
+                <dd class = "col-sm-6">
+                    @Html.DisplayFor(model => model.Country)
+                </dd>
+            </dl>
+        </div>
+    </div>
+    <div class="card">
+        <div class="card-header pb-1">
+            <h6>Sonstige Daten</h6>
+        </div>
+        <div class="card-body">
+            <dl class="row">
+                <dt class = "col-sm-6">
+                    @Html.DisplayNameFor(model => model.IsBusiness)
+                </dt>
+                <dd class = "col-sm-6">
+                    @Html.YesNoBadgeFor(model => model.IsBusiness)
+                </dd>
+            </dl>
+        </div>
+    </div>
+</div>
+
+<hr />
+
+<div class="d-flex">
+    @Html.ActionLink("Bearbeiten", "Edit", new { id = Model.Id })
+    <div class="align-self-center ml-3">
+        <a asp-action="Index">Zurück zur Liste</a>
+    </div>
+    <div class="align-self-center ml-auto">
+        <a href="#" data-toggle="modal" data-target="#trackingModal">Änderungsinfo</a>
+    </div>
+</div>
+
+<div id="trackingModal" class="modal fade" tabindex="-1" role="dialog">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header bg-info text-white">
+                <h5 class="modal-title">Änderungsinfo - @Model.Lastname, @Model.Firstname</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <dl class="row">
+                    <dt class = "col-sm-4">
+                        @Html.DisplayNameFor(model => model.CreatedBy)
+                    </dt>
+                    <dd class = "col-sm-6">
+                        @Html.DisplayFor(model => model.CreatedBy)
+                    </dd>
+                    <dt class = "col-sm-4">
+                        @Html.DisplayNameFor(model => model.CreatedOn)
+                    </dt>
+                    <dd class = "col-sm-6">
+                        @Html.DisplayFor(model => model.CreatedOn)
+                    </dd>
+                </dl>
+                <dl class="row">
+                    <dt class = "col-sm-4">
+                        @Html.DisplayNameFor(model => model.ChangedBy)
+                    </dt>
+                    <dd class = "col-sm-6">
+                        @Html.DisplayFor(model => model.ChangedBy)
+                    </dd>
+                    <dt class = "col-sm-4">
+                        @Html.DisplayNameFor(model => model.ChangedOn)
+                    </dt>
+                    <dd class = "col-sm-6">
+                        @Html.DisplayFor(model => model.ChangedOn)
+                    </dd>
+                </dl>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">Schließen</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 90 - 0
GreenTree.Strohrmann.ERP.Web/Views/Customer/Edit.cshtml

@@ -0,0 +1,90 @@
+@model GreenTree.Strohrmann.ERP.Web.Models.Business.CustomerModel
+
+@{
+    ViewData["Title"] = "Kunden bearbeiten";
+}
+
+<h1>Kunden bearbeiten</h1>
+
+<h4>@Model.Lastname, @Model.Firstname</h4>
+
+<hr />
+
+<form asp-action="Edit">
+    <div asp-validation-summary="ModelOnly" class="text-danger"></div>
+    <input asp-for="Id" type="hidden" class="form-control" />
+    <div class="card-deck">
+        <div class="card bg-light" style="max-width: 368px">
+            <div class="card-header pb-1">
+                <h6>Kundenname / -firma</h6>
+            </div>
+            <div class="card-body">
+                <div class="form-group">
+                    <label asp-for="Firstname" class="control-label"></label>
+                    <input asp-for="Firstname" class="form-control" />
+                    <span asp-validation-for="Firstname" class="text-danger"></span>
+                </div>
+                <div class="form-group">
+                    <label asp-for="Lastname" class="control-label"></label>
+                    <input asp-for="Lastname" class="form-control" />
+                    <span asp-validation-for="Lastname" class="text-danger"></span>
+                </div>
+                <div class="form-group">
+                    <label asp-for="CompanyName" class="control-label"></label>
+                    <input asp-for="CompanyName" class="form-control" />
+                    <span asp-validation-for="CompanyName" class="text-danger"></span>
+                </div>
+            </div>
+        </div>
+        <div class="card bg-light" style="max-width: 368px">
+            <div class="card-header pb-1">
+                <h6>Adressdaten</h6>
+            </div>
+            <div class="card-body">
+                <div class="form-group">
+                    <label asp-for="Address" class="control-label"></label>
+                    <input asp-for="Address" class="form-control" />
+                    <span asp-validation-for="Address" class="text-danger"></span>
+                </div>
+                <div class="form-group">
+                    <label asp-for="Town" class="control-label"></label>
+                    <input asp-for="Town" class="form-control" />
+                    <span asp-validation-for="Town" class="text-danger"></span>
+                </div>
+                <div class="form-group">
+                    <label asp-for="ZipCode" class="control-label"></label>
+                    <input asp-for="ZipCode" class="form-control" />
+                    <span asp-validation-for="ZipCode" class="text-danger"></span>
+                </div>
+                <div class="form-group">
+                    <label asp-for="Country" class="control-label"></label>
+                    @Html.CountrySelectionFor(m => m.Country, new { @class = "form-control" })
+                    <span asp-validation-for="Country" class="text-danger"></span>
+                </div>
+            </div>
+        </div>
+        <div class="card bg-light" style="max-width: 368px">
+            <div class="card-header pb-1">
+                <h6>Sonstige Daten</h6>
+            </div>
+            <div class="card-body">
+                <div class="form-group">
+                    <label asp-for="IsBusiness" class="control-label"></label>
+                    <select asp-for="IsBusiness" class="form-control">
+                        <option value="true">Ja</option>
+                        <option value="false">Nein</option>
+                    </select>
+                </div>
+            </div>
+        </div>
+    </div>
+
+    <hr />
+
+    <div class="form-group d-flex mt-3">
+        <input type="submit" value="Speichern" class="btn btn-primary" />
+        <div class="align-self-center ml-3">
+            <a asp-action="Index">Zurück zur Liste</a>
+        </div>
+    </div>
+</form>

+ 3 - 1
GreenTree.Strohrmann.ERP.Web/Views/Customer/Index.cshtml

@@ -114,7 +114,9 @@
             <th>
                 @Html.DisplayNameFor(model => model.Country)
             </th>
-            <th></th>
+            <th data-priority="1">
+                Aktionen
+            </th>
         </tr>
     </thead>
     <tbody>