)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Product (Ia.Simple.Cl.Models.Data.SmartDeals)

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

    1: using System;
    2: using System.Collections.Generic;
    3: using System.IO;
    4: using System.Linq;
    5: using System.Reflection;
    6: using System.Xml.Linq;
    7:  
    8: namespace Ia.Simple.Cl.Models.Data.SmartDeals
    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 Product
   30:     {
   31:         private static List<Product> list;
   32:  
   33:         private static readonly object objectLock = new object();
   34:  
   35:         /// <summary/>
   36:         public string Name { get; set; }
   37:  
   38:         /// <summary/>
   39:         public string Model { get; set; }
   40:  
   41:         /// <summary/>
   42:         public string Description { get; set; }
   43:  
   44:         /// <summary/>
   45:         public string ArabicDescription { get; set; }
   46:  
   47:         /// <summary/>
   48:         public string Price { get; set; }
   49:  
   50:         /// <summary/>
   51:         public List<string> ImageFileNameList { get; set; }
   52:  
   53:         /// <summary/>
   54:         public Category Category { get; set; }
   55:  
   56:         /// <summary/>
   57:         public Product() { }
   58:  
   59:         ////////////////////////////////////////////////////////////////////////////
   60:  
   61:         /// <summary>
   62:         /// 
   63:         /// </summary>
   64:         public static List<Product> ProductByCategoryId(int categoryId)
   65:         {
   66:             var li = (from l in list where l.Category.Id == categoryId select l).ToList();
   67:  
   68:             return li;
   69:         }
   70:  
   71:         ////////////////////////////////////////////////////////////////////////////
   72:  
   73:         /// <summary>
   74:         /// 
   75:         /// </summary>
   76:         public static string ConvertImageUrlToSquare300ImageUrl(string imageUrl)
   77:         {
   78:             string s;
   79:  
   80:             if (!string.IsNullOrEmpty(imageUrl))
   81:             {
   82:                 s = imageUrl.Replace(".", "-300x300.");
   83:             }
   84:             else s = string.Empty;
   85:  
   86:             return s;
   87:         }
   88:  
   89:         ////////////////////////////////////////////////////////////////////////////
   90:  
   91:         /// <summary>
   92:         /// 
   93:         /// </summary>
   94:         public static Product Random
   95:         {
   96:             get
   97:             {
   98:                 int count = List.Count;
   99:  
  100:                 return List[Ia.Cl.Models.Default.Random(count)];
  101:             }
  102:         }
  103:  
  104:         ////////////////////////////////////////////////////////////////////////////
  105:  
  106:         /// <summary>
  107:         /// 
  108:         /// </summary>
  109:         public static string Srcset
  110:         {
  111:             get
  112:             {
  113:                 // <img src="<%#Eval("Square300ImageHtmlUrl") %>" _alt="<%#Eval("ArabicDescription") %>" width="300" height="300" class="attachment-woocommerce_thumbnail size-woocommerce_thumbnail" alt="" loading="lazy" _srcset="https://teebtree.com/wp-content/uploads/2021/05/Bundel-300x300.jpeg 300w, https://teebtree.com/wp-content/uploads/2021/05/Bundel-400x400.jpeg 400w, https://teebtree.com/wp-content/uploads/2021/05/Bundel-800x800.jpeg 800w, https://teebtree.com/wp-content/uploads/2021/05/Bundel-280x280.jpeg 280w, https://teebtree.com/wp-content/uploads/2021/05/Bundel-768x768.jpeg 768w, https://teebtree.com/wp-content/uploads/2021/05/Bundel-600x600.jpeg 600w, https://teebtree.com/wp-content/uploads/2021/05/Bundel-100x100.jpeg 100w, https://teebtree.com/wp-content/uploads/2021/05/Bundel.jpeg 1000w" sizes="(max-width: 300px) 100vw, 300px" />                                                      
  114:  
  115:                 return string.Empty;
  116:             }
  117:         }
  118:  
  119:         ////////////////////////////////////////////////////////////////////////////
  120:  
  121:         /// <summary>
  122:         /// 
  123:         /// </summary>
  124:         public static List<Product> List
  125:         {
  126:             get
  127:             {
  128:                 if (list == null || list.Count == 0)
  129:                 {
  130:                     lock (objectLock)
  131:                     {
  132:                         list = new List<Product>();
  133:  
  134:                         var categoryList = Ia.Simple.Cl.Models.Data.SmartDeals.Category.List;
  135:  
  136:                         foreach (XElement xe in Ia.Simple.Cl.Models.Data.SmartDeals.Default.XDocument.Element("smartDeals").Elements("categories").Elements("category").Elements("products").Elements("product"))
  137:                         {
  138:                             var product = new Product();
  139:  
  140:                             product.Name = xe.Attribute("name").Value;
  141:                             product.Model = xe.Attribute("model").Value;
  142:                             product.Description = xe.Attribute("description").Value;
  143:                             product.ArabicDescription = xe.Attribute("arabicDescription").Value;
  144:                             product.Price = xe.Attribute("price").Value;
  145:  
  146:                             product.ImageFileNameList = new List<string>();
  147:  
  148:                             foreach (var xe2 in xe.Elements("image"))
  149:                             {
  150:                                 product.ImageFileNameList.Add(xe2.Value);
  151:                             }
  152:  
  153:                             var categoryId = int.Parse(xe.Parent.Parent.Attribute("id").Value);
  154:  
  155:                             product.Category = (from c in categoryList
  156:                                                 where c.Id == categoryId
  157:                                                 select c).Single();
  158:  
  159:                             list.Add(product);
  160:                         }
  161:                     }
  162:                 }
  163:  
  164:                 return list;
  165:             }
  166:         }
  167:  
  168:         ////////////////////////////////////////////////////////////////////////////
  169:         ////////////////////////////////////////////////////////////////////////////
  170:     }
  171:  
  172:     ////////////////////////////////////////////////////////////////////////////
  173:     ////////////////////////////////////////////////////////////////////////////
  174: }