)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » ListController (Ia.Statistics.Wa.Controllers)

Public general use code classes and xml files that we've compiled and used over the years:

    1: using Ia.Statistics.Wa.Models;
    2: using Microsoft.AspNetCore.Mvc;
    3: using System.Diagnostics;
    4: using System.Net;
    5: using System.Text;
    6: using System.Text.RegularExpressions;
    7:  
    8: namespace Ia.Statistics.Wa.Controllers
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     ///
   14:     /// </summary>
   15:     /// 
   16:     /// <remarks> 
   17:     /// Copyright � 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   18:     ///
   19:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   20:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   21:     ///
   22:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   23:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   24:     /// 
   25:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   26:     /// 
   27:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   28:     /// </remarks> 
   29:     public class ListController : Controller
   30:     {
   31:         private readonly ILogger<ListController> _logger;
   32:  
   33:         /////////////////////////////////////////////////////////////////////////////////
   34:  
   35:         /// <summary>
   36:         ///
   37:         /// </summary>
   38:         public ListController(ILogger<ListController> logger)
   39:         {
   40:             _logger = logger;
   41:         }
   42:  
   43:         /////////////////////////////////////////////////////////////////////////////////
   44:  
   45:         /// <summary>
   46:         ///
   47:         /// </summary>
   48:         public IActionResult Index(string siteId)
   49:         {
   50:             var indexViewModel = new Ia.Statistics.Wa.Models.Home.IndexViewModel();
   51:  
   52:             if (!string.IsNullOrEmpty(siteId))
   53:             {
   54:                 if (int.TryParse(siteId, out int i))
   55:                 {
   56:                     List_DataBind(ref indexViewModel, i);
   57:                 }
   58:             }
   59:  
   60:             return View(indexViewModel);
   61:         }
   62:  
   63:         /////////////////////////////////////////////////////////////////////////////////
   64:  
   65:         /// <summary>
   66:         ///
   67:         /// </summary>
   68:         [Route("/product")]
   69:         public IActionResult Product(string productId)
   70:         {
   71:             var productViewModel = new Ia.Statistics.Wa.Models.List.ProductViewModel();
   72:  
   73:             if (!string.IsNullOrEmpty(productId))
   74:             {
   75:                 Product_DataBind(ref productViewModel, productId);
   76:             }
   77:  
   78:             return View(productViewModel);
   79:         }
   80:  
   81:         ////////////////////////////////////////////////////////////////////////////
   82:         ////////////////////////////////////////////////////////////////////////////
   83:  
   84:         /// <summary>
   85:         ///
   86:         /// </summary>
   87:         private void List_DataBind(ref Ia.Statistics.Wa.Models.Home.IndexViewModel indexViewModel, int siteId)
   88:         {
   89:             var site = Ia.Statistics.Cl.Models.Site.SiteFromId(siteId);
   90:  
   91:             if (site != null)
   92:             {
   93:                 var productPriceStockQuantitySoldList = Ia.Statistics.Cl.Models.ProductPriceStockQuantitySold.ListBySiteId(site.Id);
   94:  
   95:                 var s = string.Empty;
   96:  
   97:                 s += "Site: " + site.Name + " (" + site.BaseUrl + ")\r\n";
   98:                 s += "Products: " + productPriceStockQuantitySoldList.Count + "\r\n";
   99:  
  100:                 var list = (from p in productPriceStockQuantitySoldList
  101:                             select p).ToList();
  102:  
  103:                 var sb = new StringBuilder();
  104:  
  105:                 sb.AppendLine("Name\tPrice\tStock\tQuantitySold");
  106:  
  107:                 foreach (var l in list)
  108:                 {
  109:                     sb.AppendLine(l.Product.Name + "\t" + l.Price + "\t" + l.Stock + "\t" + l.QuantitySold);
  110:                 }
  111:  
  112:                 indexViewModel.ListLabel = s;
  113:  
  114:                 indexViewModel.ListLiteral = sb.ToString();
  115:             }
  116:             else
  117:             {
  118:             }
  119:         }
  120:  
  121:         ////////////////////////////////////////////////////////////////////////////
  122:  
  123:         /// <summary>
  124:         ///
  125:         /// </summary>
  126:         private void Product_DataBind(ref Ia.Statistics.Wa.Models.List.ProductViewModel productViewModel, string productId)
  127:         {
  128:             var product = Ia.Statistics.Cl.Models.Product.ById(productId);
  129:  
  130:             if (product != null)
  131:             {
  132:                 var productPriceSpotList = Ia.Statistics.Cl.Models.ProductPriceSpot.ListByProductId(product.Id);
  133:                 var productStockSpotList = Ia.Statistics.Cl.Models.ProductStockSpot.ListByProductId(product.Id);
  134:  
  135:                 var site = Ia.Statistics.Cl.Models.Site.SiteFromId(product.SiteId);
  136:  
  137:                 productViewModel.ProductId = productId;
  138:                 productViewModel.ProductName = product.Name;
  139:                 productViewModel.SiteName = site.Name;
  140:                 productViewModel.SiteUrl = site.BaseUrl;
  141:  
  142:                 productViewModel.Sku = product.Sku;
  143:                 productViewModel.ProductUrl = product.Url;
  144:  
  145:                 PriceChart_DataBind(ref productViewModel, productPriceSpotList);
  146:  
  147:                 StockChart_DataBind(ref productViewModel, productStockSpotList);
  148:             }
  149:             else
  150:             {
  151:             }
  152:         }
  153:  
  154:         ////////////////////////////////////////////////////////////////////////////
  155:  
  156:         /// <summary>
  157:         ///
  158:         /// </summary>
  159:         private void PriceChart_DataBind(ref Ia.Statistics.Wa.Models.List.ProductViewModel productViewModel, List<Ia.Statistics.Cl.Models.ProductPriceSpot> productPriceSpotList)
  160:         {
  161:             productViewModel.PriceChartLabels = (from l in productPriceSpotList select l.Created.ToString("yyyy-MM-dd")).ToList();
  162:  
  163:             productViewModel.PriceChartLabel1 = "Price";
  164:             productViewModel.PriceChartDecimalData1 = (from l in productPriceSpotList select l.Price).ToList();
  165:         }
  166:  
  167:         ////////////////////////////////////////////////////////////////////////////
  168:  
  169:         /// <summary>
  170:         ///
  171:         /// </summary>
  172:         private void StockChart_DataBind(ref Ia.Statistics.Wa.Models.List.ProductViewModel productViewModel, List<Ia.Statistics.Cl.Models.ProductStockSpot> productStockSpotList)
  173:         {
  174:             productViewModel.StockChartLabels = (from l in productStockSpotList select l.Created.ToString("yyyy-MM-dd")).ToList();
  175:  
  176:             productViewModel.StockChartLabel1 = "Stock";
  177:             productViewModel.StockChartData1 = (from l in productStockSpotList select l.Stock).ToList();
  178:         }
  179:  
  180:         /////////////////////////////////////////////////////////////////////////////////
  181:  
  182:         /// <summary>
  183:         ///
  184:         /// </summary>
  185:         [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
  186:         public IActionResult Error()
  187:         {
  188:             return View(new Ia.Statistics.Wa.Models.ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
  189:         }
  190:  
  191:         /////////////////////////////////////////////////////////////////////////////////
  192:         /////////////////////////////////////////////////////////////////////////////////
  193:     }
  194:  
  195:     /////////////////////////////////////////////////////////////////////////////////
  196:     /////////////////////////////////////////////////////////////////////////////////
  197: }