public ActionResult Filter(ProductsFilters filtersEvents)
        {
            var prodFilter = filtersEvents.Name;
            var products   = _productBusinessLogic
                             .GetAll()
                             .Where(@prod =>
                                    FilterByName(@prod, prodFilter))
                             .ToList();
            List <ProductView> models = new List <ProductView>();

            foreach (var item in products)
            {
                models.Add(_mapper.Map <ProductView>(item));
            }
            ViewBag.Data = models.OrderBy(x => x.Name).ToList();
            return(View(nameof(Index)));
        }
Exemple #2
0
        public string GetFilters()
        {
            var _colorRep    = new ProductColorRepository(_context);
            var _metalRep    = new ProductMetalRepository(_context);
            var _typeRep     = new ProductTypeRepository(_context);
            var _statusRep   = new ProductStatusRepository(_context);
            var _statusAvRep = new ProductAvStatusRepository(_context);
            var _genderRep   = new GenderRepository(_context);


            var filters = new ProductsFilters()
            {
                ColorList    = _colorRep.GetAllAvailable().Select(_mapper.Map <ProductColorView>),
                MetalList    = _metalRep.GetAllAvailable(),
                GenderList   = _genderRep.GetAllAvailable(),
                TypeList     = _typeRep.GetAllAvailable(),
                StatusList   = _statusRep.GetAllAvailable(),
                StatusAvList = _statusAvRep.GetAllAvailable()
            };

            ViewBag.Data = JsonConvert.SerializeObject(filters);
            return(ViewBag.Data);
        }
Exemple #3
0
        #pragma warning disable 1998
        public async override global::System.Threading.Tasks.Task ExecuteAsync()
        {
            BeginContext(155, 2, true);
            WriteLiteral("\r\n");
            EndContext();
#line 7 "E:\INTITA\InternetStore\DocsExchange\Views\Catalog\Index.cshtml"

            ViewData["Title"] = "Каталог товарів";

#line default
#line hidden
            BeginContext(208, 2, true);
            WriteLiteral("\r\n");
            EndContext();
#line 11 "E:\INTITA\InternetStore\DocsExchange\Views\Catalog\Index.cshtml"

            //List<ProductView> prodList = ViewBag.Data;
            //string prodList = JsonConvert.SerializeObject(ViewBag.Data);
            string          prodList = ViewBag.Data;
            ProductsFilters filters  = ViewBag.Filters;

#line default
#line hidden
            BeginContext(420, 2, true);
            WriteLiteral("\r\n");
            EndContext();
            BeginContext(422, 48, false);
            __tagHelperExecutionContext = __tagHelperScopeManager.Begin("link", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagOnly, "27e060da780243f2ba54dd38cb828f67", async() => {
            }
                                                                        );
            __Microsoft_AspNetCore_Mvc_Razor_TagHelpers_UrlResolutionTagHelper = CreateTagHelper <global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper>();
            __tagHelperExecutionContext.Add(__Microsoft_AspNetCore_Mvc_Razor_TagHelpers_UrlResolutionTagHelper);
            __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_0);
            __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_1);
            await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);

            if (!__tagHelperExecutionContext.Output.IsContentModified)
            {
                await __tagHelperExecutionContext.SetOutputContentAsync();
            }
            Write(__tagHelperExecutionContext.Output);
            __tagHelperExecutionContext = __tagHelperScopeManager.End();
            EndContext();
            BeginContext(470, 4, true);
            WriteLiteral("\r\n\r\n");
            EndContext();
            DefineSection("Scripts", async() => {
                BeginContext(492, 1404, true);
                WriteLiteral(@"

    <link rel=""stylesheet"" href=""//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"">
    <script src=""https://code.jquery.com/ui/1.12.1/jquery-ui.js""></script>

    <script type=""text/javascript"">

        //$("".filterJS"").change(function setStatus() {
        function Check() {
            var filtersArr = [];
            var elements = document.getElementsByClassName('filter');
            for (let item of elements) {
                filtersArr.push({ Id: item.id, Checked: item.checked });
            }
            var filters = JSON.stringify(filtersArr);
            $.ajax({
                url: '/Filter/Filter',
                type: ""POST"",
                data: JSON.stringify(filters),
                contentType: ""application/json; charset=utf-8"",
                dataType: ""json"",
                success: function (data) {
                    loadGoods(data);
                },
                error: function (response) {
                    console.log(response.response");
                WriteLiteral(@"Text);
                },
                failure: function (response) {
                    console.log(response.responseText);
                }
            })
        };
        //});
        $(document).ready(function () {
            loadFilters();
            loadGoods();
        });
        function loadFilters(){
            $.ajax({
                url: '");
                EndContext();
                BeginContext(1897, 34, false);
#line 59 "E:\INTITA\InternetStore\DocsExchange\Views\Catalog\Index.cshtml"
                Write(Url.Action("GetFilters", "Filter"));

#line default
#line hidden
                EndContext();
                BeginContext(1931, 3013, true);
                WriteLiteral(@"',
                type: ""GET"",
                contentType: ""application/json; charset=utf-8"",
                dataType: ""json"",
                success: function (filters) {
                    rawFilters(filters);
                }
            });
        }
        function clearElem(elementID)
        {
            document.getElementById(elementID).innerHTML = """";
        }
        function rawFilters(filters) {
            var ColorList = filters.ColorList;
            var MetalList = filters.MetalList;
            var GenderList = filters.GenderList;
            var TypeList = filters.TypeList;
            var StatusList = filters.StatusList;
            var StatusAvList = filters.StatusAvList;

            var tb = document.getElementById('table-filters');
            var field = document.createElement('fieldset');
            tb.appendChild(field);
            var div = document.createElement('div');
            div.setAttribute(""id"", ""checkboxes"");

            addUl(div, ");
                WriteLiteral(@"field, MetalList, ""metal_"", ""Тип металу:"");
            addUl(div, field, ColorList, ""color_"", ""Колір:"");
            addUl(div, field, GenderList, ""gender_"", ""Стать:"");
            addUl(div, field, TypeList, ""type_"", ""Тип виробу:"");
            addUl(div, field, StatusList, ""status_"", ""Новинки:"");
            addUl(div,field,StatusAvList,""statusav_"",""Наявніст:"");
        }
        function rawGoods(data) {
            clearElem(""productTable"");
            var tbody = document.getElementById('productTable');
            
            data.forEach(element => {
                var tr = document.createElement(""tr"");
                tbody.appendChild(tr);
                
                console.log(element);
                var td = document.createElement('td');
                td.setAttribute(""class"",""col-lg-2"");
                tr.appendChild(td);
                td.innerHTML = element.Name;
                
            });
        };
        function addUl(div,field, list, pref, leb) {");
                WriteLiteral(@"
            var ul = document.createElement('ul');
            var label = document.createElement('label');
            field.appendChild(div);
            label.innerHTML = leb;
            div.appendChild(label);
            ul.setAttribute(""class"", ""ulCheckboxes"");
            div.appendChild(ul);
            list.forEach(element => {
                var li = document.createElement('li');
                ul.appendChild(li);
                var inp = document.createElement(""INPUT"");
                inp.setAttribute(""type"", ""checkbox"");
                inp.setAttribute(""class"", ""filter"");
                inp.setAttribute(""id"", pref + element.Id);
                inp.setAttribute(""onclick"", ""Check()"");
                li.appendChild(inp);
                li.append(element.Name);
            });
        }
        function loadGoods(data = null) {
            if (data == null) {
                $.ajax({
                    url: '");
                EndContext();
                BeginContext(4945, 33, false);
#line 132 "E:\INTITA\InternetStore\DocsExchange\Views\Catalog\Index.cshtml"
                Write(Url.Action("getGoods", "Catalog"));

#line default
#line hidden
                EndContext();
                BeginContext(4978, 375, true);
                WriteLiteral(@"',
                    type: ""GET"",
                    contentType: ""application/json; charset=utf-8"",
                    dataType: ""json"",
                    success: function (data) {
                        rawGoods(data);
                    }
                });
            } else {
                rawGoods(data);
            }
        }
    </script>
");
                EndContext();
            }
                          );
            BeginContext(5356, 617, true);
            WriteLiteral(@"<h2>Каталог товарів</h2>

<table class=""table col-lg-10"">
    <thead>
        <tr>
            <th class=""col-lg-1"">Фільтри</th>
            <th class=""col-lg-2"">Назва</th>
            <th class=""col-lg-1"">Тип товару</th>
            <th class=""col-lg-1"">Тип металу</th>
            <th class=""col-lg-1"">Колір</th>
            <th class=""col-lg-1"">Стать</th>
            <th class=""col-lg-1"">Вага</th>
            <th class=""col-lg-1"">Кількість</th>
            <th class=""col-lg-1"">Ціна</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class=""col-lg-1"" id=""table-filters"">
");
            EndContext();
            BeginContext(9336, 162, true);
            WriteLiteral("            </td>\r\n            <td class=\"col-lg-2\" >\r\n                <table class=\"table col-lg-9\">\r\n                    <thead>\r\n                        <tr>\r\n");
            EndContext();
            BeginContext(10002, 108, true);
            WriteLiteral("                        </tr>\r\n                    </thead>\r\n                    <tbody id=\"productTable\">\r\n");
            EndContext();
            BeginContext(11196, 114, true);
            WriteLiteral("                    </tbody>\r\n                </table>\r\n            </td>\r\n        </tr>\r\n    </tbody>\r\n</table>\r\n");
            EndContext();
        }