using System.Collections.Generic; using System.Linq; using System.Web.Mvc; namespace ShwasherSys.Models.Layout { public class SearchFormViewModal { public SearchFormViewModal(List searchItems,string formId="search-form", bool isSingle = false) { SearchItems = searchItems; IsSingle = isSingle; FormId = formId; } public SearchFormViewModal(List searchItems, bool isSingle ) { SearchItems = searchItems; IsSingle = isSingle; FormId = "search-form"; } public bool IsSingle { get; set; } public string FormId { get; set; } public List SearchItems { get; set; } } public class SearchItem { public SearchItem(string field, string displayName, FiledType filedType = FiledType.S, ExpType expType = ExpType.Contains,string value="", string formId = "",string showField="") { Field = field; DisplayName = displayName; FiledType = filedType; ExpType = expType; if (FiledType != FiledType.S) { ExpType = ExpType == ExpType.Contains ? ExpType.Equal : expType; } SelectItems = new List(); Value = value; FormId = formId; ShowField = showField; } public string FormId { get; set; } public string Field { get; set; } public string DisplayName { get; set; } public string SearchModalId { get; set; } public FiledType FiledType { get; set; } public ExpType ExpType { get; set; } public List SelectItems { get; set; } public string Value { get; set; } public string ShowField { get; set; } public string SelectItemStr { get { if (!SelectItems.Any()) { return ""; } string str = ""; foreach (var searchItemSelect in SelectItems) { str += $"\"{searchItemSelect.Filed}\":\""; foreach (var item in searchItemSelect.Items) { str += $""; } str += "\""; } return str; } } private string _target; public string Target => !string.IsNullOrEmpty(_target) ? _target : ""; public SearchItem SetSearchIcon(string modalId,string target = null) { SearchModalId = modalId; _target = target; return this; } public SearchItem SetSearchItem(List items, string filed = null,bool isAddBlank=true) { filed = filed ?? Field; SelectItems.Add(new SearchItemSelect(filed, items,isAddBlank)); ExpType = ExpType == ExpType.Contains ? ExpType.Equal : ExpType; return this; } } public class SearchItemSelect { public SearchItemSelect(string filed, List items) { Filed = filed; Items = items; IsAddBlank = true; } public SearchItemSelect(string filed, List items,bool isAddBlank) { Filed = filed; Items = items; IsAddBlank = isAddBlank; } public bool IsAddBlank { get; set; } public string Filed { get; set; } public List Items { get; set; } } public enum FiledType { /// /// string /// S = 0, /// /// int /// I = 1, /// /// int? /// Inull = 2, /// /// bool /// B = 3, /// /// bool? /// Bnull = 4, /// /// Datetime /// D = 5, /// /// Datetime? /// Dnull = 6, /// /// Decimal /// Dec = 7, /// /// Decimal? /// DecNull = 8 } public enum ExpType { Equal , NotEqual , Greater , Less , GreaterOrEqual , LessOrEqual , Contains , NotContains } }