Kaynağa Gözat

Kundensuche fast abgeschlossen

Arne Diekmann 5 yıl önce
ebeveyn
işleme
0be370af4c

+ 16 - 0
GreenTree.Strohrmann.ERP.Web/Controllers/CraftController.cs

@@ -63,6 +63,10 @@ namespace GreenTree.Strohrmann.ERP.Web.Controllers
         // GET: CraftController/Create
         public ActionResult Create()
         {
+            ViewData.AddSelectList("AvailableEmployees",
+                _eRPDbContext.Employees,
+                e => e.Id, e => String.Format("{0} {1}", e.Firstname, e.Lastname));
+
             return View();
         }
 
@@ -73,6 +77,10 @@ namespace GreenTree.Strohrmann.ERP.Web.Controllers
         {
             if (!ModelState.IsValid)
             {
+                ViewData.AddSelectList("AvailableEmployees",
+                    _eRPDbContext.Employees,
+                    e => e.Id, e => String.Format("{0} {1}", e.Firstname, e.Lastname));
+
                 return View(model);
             }
 
@@ -97,6 +105,10 @@ namespace GreenTree.Strohrmann.ERP.Web.Controllers
         // GET: CraftController/Edit/5
         public ActionResult Edit(int id)
         {
+            ViewData.AddSelectList("AvailableEmployees",
+                _eRPDbContext.Employees,
+                e => e.Id, e => String.Format("{0} {1}", e.Firstname, e.Lastname));
+
             var craft = _eRPDbContext.Crafts
                 .FirstOrDefault(c => c.Id == id);
 
@@ -112,6 +124,10 @@ namespace GreenTree.Strohrmann.ERP.Web.Controllers
         {
             if (!ModelState.IsValid)
             {
+                ViewData.AddSelectList("AvailableEmployees",
+                    _eRPDbContext.Employees,
+                    e => e.Id, e => String.Format("{0} {1}", e.Firstname, e.Lastname));
+
                 return View(model);
             }
 

+ 3 - 3
GreenTree.Strohrmann.ERP.Web/Controllers/CustomerController.cs

@@ -169,9 +169,9 @@ namespace GreenTree.Strohrmann.ERP.Web.Controllers
                 return new JsonResult(null);
 
             var result = _eRPDbContext.Customers
-                .Where(c => c.Firstname.Contains(search.SearchTerm) ||
-                            c.Lastname.Contains(search.SearchTerm) ||
-                            c.CompanyName.Contains(search.SearchTerm))
+                .Where(c => c.Firstname.Contains(search.SearchTerm, StringComparison.OrdinalIgnoreCase) ||
+                            c.Lastname.Contains(search.SearchTerm, StringComparison.OrdinalIgnoreCase) ||
+                            c.CompanyName.Contains(search.SearchTerm, StringComparison.OrdinalIgnoreCase))
                 .ToArray()
                 .Select(c => new CustomerModel(c));
 

+ 1 - 1
GreenTree.Strohrmann.ERP.Web/Models/Business/CraftEmployeeModel.cs

@@ -32,7 +32,7 @@ namespace GreenTree.Strohrmann.ERP.Web.Models.Business
         /// <summary>
         /// Employee id
         /// </summary>
-        [Display(Name = "Mitarbeiter ID")]
+        [Display(Name = "Mitarbeiter")]
         public int EmployeeId { get; set; }
 
         /// <summary>

+ 2 - 1
GreenTree.Strohrmann.ERP.Web/Models/Business/CraftModel.cs

@@ -1,4 +1,5 @@
 using GreenTree.Strohrmann.ERP.Core.Domain.Business;
+using GreenTree.Strohrmann.ERP.Web.Models.Search;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
@@ -7,7 +8,7 @@ using System.Threading.Tasks;
 
 namespace GreenTree.Strohrmann.ERP.Web.Models.Business
 {
-    public class CraftModel
+    public class CraftModel : ICustomerSearchable
     {
         #region Properties
 

+ 12 - 0
GreenTree.Strohrmann.ERP.Web/Models/Business/CustomerModel.cs

@@ -78,6 +78,18 @@ namespace GreenTree.Strohrmann.ERP.Web.Models.Business
         [Display(Name = "Postleitzahl")]
         public string ZipCode { get; set; }
 
+        /// <summary>
+        /// Local full name
+        /// </summary>
+        [Display(Name = "Lokale Adresse")]
+        public string LocalAddress
+        {
+            get
+            {
+                return String.Format("{0}, {1} {2}", Address, ZipCode, Town);
+            }
+        }
+
         /// <summary>
         /// Customer country
         /// </summary>

+ 15 - 0
GreenTree.Strohrmann.ERP.Web/Models/Search/ICustomerSearchable.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace GreenTree.Strohrmann.ERP.Web.Models.Search
+{
+    public interface ICustomerSearchable
+    {
+        /// <summary>
+        /// Model class searchable for customer id
+        /// </summary>
+        public int CustomerId { get; set; }
+    }
+}

+ 24 - 1
GreenTree.Strohrmann.ERP.Web/Models/Shared/SearchModel.cs

@@ -1,4 +1,5 @@
-using System;
+using Microsoft.EntityFrameworkCore.Metadata.Internal;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
@@ -7,6 +8,8 @@ namespace GreenTree.Strohrmann.ERP.Web.Models.Shared
 {
     public class SearchModel
     {
+        #region Properties
+
         /// <summary>
         /// Path of the model property
         /// </summary>
@@ -16,5 +19,25 @@ namespace GreenTree.Strohrmann.ERP.Web.Models.Shared
         /// Term to be searched for
         /// </summary>
         public string SearchTerm { get; set; }
+
+        #endregion
+
+        #region Ctor
+
+        /// <summary>
+        /// Initializes a new instance of the SearchModel class
+        /// </summary>
+        public SearchModel() {  }
+
+        /// <summary>
+        /// Initializes a new instance of the SearchModel class
+        /// </summary>
+        /// <param name="modelPropertyPath">The path of the model property.</param>
+        public SearchModel(string modelPropertyPath) 
+        {
+            ModelPropertyPath = modelPropertyPath;
+        }
+
+        #endregion
     }
 }

+ 3 - 1
GreenTree.Strohrmann.ERP.Web/Views/Craft/_CraftEmployeePartial.cshtml

@@ -3,7 +3,9 @@
 <div class="row">
     <div class="form-group col-md-4">
         <label asp-for="EmployeeId" class="control-label"></label>
-        <input asp-for="EmployeeId" name="CraftEmployees[@Model.Index].EmployeeId" class="form-control" />
+        @Html.DropDownListFor(e => e.Employee.Id, 
+            (IEnumerable<SelectListItem>)ViewData["AvailableEmployees"], 
+            new { @class = "form-control" })
         <span asp-validation-for="EmployeeId" class="text-danger"></span>
     </div>
     <div class="form-group col-md-4">

+ 50 - 21
GreenTree.Strohrmann.ERP.Web/Views/Customer/_SearchCustomerPartial.cshtml

@@ -1,4 +1,4 @@
-@model GreenTree.Strohrmann.ERP.Web.Models.Shared.SearchModel
+@model GreenTree.Strohrmann.ERP.Web.Models.Search.ICustomerSearchable
 
 @{ 
 	var partialId = Html.RandomId();
@@ -8,6 +8,22 @@
 
     @{ 
         <text>
+        $(document).ready(function () {
+            $("#text_@partialId").on('keypress', function (e) {
+                if (e.keyCode == 13) {
+                    search_@partialId ();
+                    e.preventDefault();
+                };
+            });
+            $("#text_@partialId").on('keydown', function (e) {
+                if (e.keyCode == 8 && $("#value_@partialId").val() != "") {
+                    $("#text_@partialId").val("");
+                    $("#value_@partialId").val("");
+                    e.preventDefault();
+                };
+            });
+        });
+
         function search_@partialId () {
             $.ajax({
                 method: "POST",
@@ -16,19 +32,41 @@
                     SearchTerm: $("#text_@partialId").val()
                 },
                 success: function (data) {
-                    debugger;
-                    $("#searchCustomerModal_@partialId").modal("show");
-                    if (data == null) return;
-                    $(data).each(function (index, element) {
+                    $("#searchCustomerModal_@partialId").find(".list-group").empty();
+                    if (data.length > 0) {
+                        $(data).each(function (index, elem) {
+                            $("#searchCustomerModal_@partialId").find(".list-group").append(
+                                '<a href="#" class="list-group-item list-group-item-info list-group-item-action" ' +
+                                'data-toggle="list" data-val="{0}" data-text="{1}">{1} ({2})</a>'
+                                    .format(elem.id, elem.fullname, elem.localAddress));
+                            $("#searchCustomerModal_@partialId").find(".list-group").append(
+                                '<a href="#" class="list-group-item list-group-item-info list-group-item-action" ' +
+                                'data-toggle="list" data-val="{0}" data-text="{1}">{1} ({2})</a>'
+                                    .format(elem.id, elem.fullname, elem.localAddress));
+                            $("#searchCustomerModal_@partialId").find(".list-group").append(
+                                '<a href="#" class="list-group-item list-group-item-info list-group-item-action" ' +
+                                'data-toggle="list" data-val="{0}" data-text="{1}">{1} ({2})</a>'
+                                    .format(elem.id, elem.fullname, elem.localAddress));
+                        });
+                    } else {
                         $("#searchCustomerModal_@partialId").find(".list-group").append(
-                            '<button type="button" class="list-group-item list-group-item-action">' + element + '</button>');
-                    });
+                            '<button type="button" class="list-group-item">Keine Treffer</button>');
+					}
+                    $("#searchCustomerModal_@partialId").modal("show");
                 },
                 error: function (msg) {
 
                 }
             });
         }
+
+        function select_@partialId () {
+            $("#searchCustomerModal_@partialId").modal("hide");
+            var val = $("#searchCustomerModal_@partialId").find("a.active").attr("data-val");
+            var text = $("#searchCustomerModal_@partialId").find("a.active").attr("data-text");
+            $("#value_@partialId").val(val);
+            $("#text_@partialId").val(text);
+	    }
             
         </text>
     }
@@ -37,19 +75,13 @@
 
 <div class="input-group mb-3">
     <div class="input-group-prepend">
-        <button class="btn btn-outline-secondary fas fa-search" type="button" onclick="search_@partialId ()"></button>
+        <button class="btn btn-info fas fa-search" type="button" onclick="search_@partialId ()"></button>
     </div>
     <input id="text_@partialId" type="text" class="form-control" placeholder="Suchbegriff" aria-label="Suchbegriff" aria-describedby="basic-addon1">
-    @if (Model == null)
-	{ 
-        <input id="hiddenValue_@partialId" type="hidden" />
-	}
-	else
-	{
-        <input id="hiddenValue_@partialId" type="hidden" name="@Model.ModelPropertyPath" />
-	}
 </div>
 
+<input id="value_@partialId" type="hidden" asp-for="CustomerId" />
+
 <div id="searchCustomerModal_@partialId" class="modal fade">
     <div class="modal-dialog">
         <div class="modal-content">
@@ -57,15 +89,12 @@
                 <h4 class="modal-title">Suchergebnisse</h4>
             </div>
             <div class="modal-body">
-                <div class="form-group">
-                    <label class="control-label"></label>
-                    <div class="list-group">
-                    </div>
+                <div class="list-group">
                 </div>
             </div>
             <div class="modal-footer">
                 <div class="btn btn-secondary" data-dismiss="modal">Schließen</div>
-                <div class="btn btn-success">Auswählen</div>
+                <div class="btn btn-success" onclick="select_@partialId ()">Auswählen</div>
             </div>
         </div>
     </div>

+ 13 - 0
GreenTree.Strohrmann.ERP.Web/wwwroot/js/site.js

@@ -2,3 +2,16 @@
 // for details on configuring this project to bundle and minify static web assets.
 
 // Write your JavaScript code.
+
+// First, checks if it isn't implemented yet.
+if (!String.prototype.format) {
+    String.prototype.format = function () {
+        var args = arguments;
+        return this.replace(/{(\d+)}/g, function (match, number) {
+            return typeof args[number] != 'undefined'
+                ? args[number]
+                : match
+                ;
+        });
+    };
+}