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

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

Ministry of Education Books support class for Learning data model.

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Data;
    4: using System.IO;
    5: using System.Linq;
    6: using System.Reflection;
    7: using System.Xml.Linq;
    8: using System.ComponentModel.DataAnnotations;
    9: using System.ComponentModel.DataAnnotations.Schema;
   10: using System.Web;
   11:  
   12: namespace Ia.Learning.Cl.Models
   13: {
   14:     ////////////////////////////////////////////////////////////////////////////
   15:  
   16:     /// <summary publish="true">
   17:     /// Ministry of Education Books support class for Learning data model.
   18:     /// </summary>
   19:     /// 
   20:     /// <remarks> 
   21:     /// Copyright © 2024-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   22:     ///
   23:     /// 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
   24:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   25:     ///
   26:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   27:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   28:     /// 
   29:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   30:     /// 
   31:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   32:     /// </remarks> 
   33:     public class MoeBook
   34:     {
   35:         private static XDocument xDocument;
   36:  
   37:         private static List<Ia.Learning.Cl.Models.MoeBook> levelList, gradeList, periodList, courseList;
   38:  
   39:         private static readonly object objectLock = new object();
   40:  
   41:         /// <summary/>
   42:         [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
   43:         public string Id { get; set; }
   44:  
   45:         /// <summary/>
   46:         public string LevelId { get; set; }
   47:  
   48:         /// <summary/>
   49:         public string GradeId { get; set; }
   50:  
   51:         /// <summary/>
   52:         public string PeriodId { get; set; }
   53:  
   54:         /// <summary/>
   55:         public string Name { get; set; }
   56:  
   57:         /// <summary/>
   58:         public string ArabicName { get; set; }
   59:  
   60:         /// <summary/>
   61:         public string Url { get; set; }
   62:  
   63:         /// <summary/>
   64:         public string PdfGoogleDriveFileId { get; set; }
   65:  
   66:         /// <summary/>
   67:         public string PdfDownloadedManuallyDueToSizeIssue { get; set; }
   68:  
   69:         /// <summary/>
   70:         public string PdfDownloadUrl
   71:         {
   72:             get
   73:             {
   74:                 string url;
   75:  
   76:                 if (!string.IsNullOrEmpty(PdfGoogleDriveFileId))
   77:                 {
   78:                     if (!string.IsNullOrEmpty(PdfDownloadedManuallyDueToSizeIssue))
   79:                     {
   80:                         url = "https://منهج.com/file/" + PdfDownloadedManuallyDueToSizeIssue;
   81:                     }
   82:                     else
   83:                     {
   84:                         url = @"https://drive.usercontent.google.com/u/0/uc?id=" + PdfGoogleDriveFileId + "&export=download";
   85:                     }
   86:                 }
   87:                 else url = string.Empty;
   88:  
   89:                 return url;
   90:             }
   91:         }
   92:  
   93:         /// <summary/>
   94:         public string ImageUrl
   95:         {
   96:             get { return "https://منهج.com/file/" + Id.ToString() + ".png"; }
   97:         }
   98:  
   99:         /// <summary/>
  100:         public string PdfUrl
  101:         {
  102:             get { return "https://منهج.com/file/" + Id.ToString() + ".pdf"; }
  103:         }
  104:  
  105:         /// <summary/>
  106:         public string LevelUrl
  107:         {
  108:             get { return "/level?id=" + Id.ToString(); }
  109:         }
  110:  
  111:         /// <summary/>
  112:         public string GradeUrl
  113:         {
  114:             get { return "/grade?id=" + Id.ToString(); }
  115:         }
  116:  
  117:         /// <summary/>
  118:         public string PeriodUrl
  119:         {
  120:             get { return "/period?id=" + Id.ToString(); }
  121:         }
  122:  
  123:         ////////////////////////////////////////////////////////////////////////////
  124:  
  125:         /// <summary>
  126:         ///
  127:         /// </summary>
  128:         public static string MoeBookLevelId(string levelXmlId)
  129:         {
  130:             var id = levelXmlId.PadLeft(2, '0');
  131:  
  132:             return id;
  133:         }
  134:  
  135:         ////////////////////////////////////////////////////////////////////////////
  136:  
  137:         /// <summary>
  138:         ///
  139:         /// </summary>
  140:         public static string MoeBookGradeId(string levelXmlId, string gradeXmlId)
  141:         {
  142:             var id = levelXmlId.PadLeft(2, '0') + gradeXmlId.PadLeft(2, '0');
  143:  
  144:             return id;
  145:         }
  146:  
  147:         ////////////////////////////////////////////////////////////////////////////
  148:  
  149:         /// <summary>
  150:         ///
  151:         /// </summary>
  152:         public static string MoeBookPeriodId(string levelXmlId, string gradeXmlId, string periodXmlId)
  153:         {
  154:             var id = levelXmlId.PadLeft(2, '0') + gradeXmlId.PadLeft(2, '0') + periodXmlId.PadLeft(2, '0');
  155:  
  156:             return id;
  157:         }
  158:  
  159:         ////////////////////////////////////////////////////////////////////////////
  160:  
  161:         /// <summary>
  162:         ///
  163:         /// </summary>
  164:         public static string MoeBookId(string levelXmlId, string gradeXmlId, string periodXmlId, string courseXmlId)
  165:         {
  166:             var id = levelXmlId.PadLeft(2, '0') + gradeXmlId.PadLeft(2, '0') + periodXmlId.PadLeft(2, '0') + courseXmlId.PadLeft(2, '0');
  167:  
  168:             return id;
  169:         }
  170:  
  171:         ////////////////////////////////////////////////////////////////////////////
  172:  
  173:         /// <summary>
  174:         ///
  175:         /// </summary>
  176:         public static string LevelIdFromGradeId(string gradeId)
  177:         {
  178:             var id = gradeId.Substring(0, 2);
  179:  
  180:             return id;
  181:         }
  182:  
  183:         ////////////////////////////////////////////////////////////////////////////
  184:  
  185:         /// <summary>
  186:         ///
  187:         /// </summary>
  188:         public static string LevelIdFromPeriodId(string periodId)
  189:         {
  190:             var id = periodId.Substring(0, 2);
  191:  
  192:             return id;
  193:         }
  194:  
  195:         ////////////////////////////////////////////////////////////////////////////
  196:  
  197:         /// <summary>
  198:         ///
  199:         /// </summary>
  200:         public static string LevelIdFromCourseId(string courseId)
  201:         {
  202:             var id = courseId.Substring(0, 2);
  203:  
  204:             return id;
  205:         }
  206:  
  207:         ////////////////////////////////////////////////////////////////////////////
  208:  
  209:         /// <summary>
  210:         ///
  211:         /// </summary>
  212:         public static string GradeIdFromPeriodId(string periodId)
  213:         {
  214:             var id = periodId.Substring(0, 4);
  215:  
  216:             return id;
  217:         }
  218:  
  219:         ////////////////////////////////////////////////////////////////////////////
  220:  
  221:         /// <summary>
  222:         ///
  223:         /// </summary>
  224:         public static string GradeIdFromCourseId(string courseId)
  225:         {
  226:             var id = courseId.Substring(0, 4);
  227:  
  228:             return id;
  229:         }
  230:  
  231:         ////////////////////////////////////////////////////////////////////////////
  232:  
  233:         /// <summary>
  234:         ///
  235:         /// </summary>
  236:         public static List<Ia.Learning.Cl.Models.MoeBook> LevelList
  237:         {
  238:             get
  239:             {
  240:                 if (levelList == null || levelList.Count == 0)
  241:                 {
  242:                     levelList = (from xElement in XDocument.Element("ministry-of-education-books").Descendants("level")
  243:                                  where xElement.HasElements
  244:                                  select new Ia.Learning.Cl.Models.MoeBook
  245:                                  {
  246:                                      Id = Ia.Learning.Cl.Models.MoeBook.MoeBookLevelId(xElement.Attribute("id").Value),
  247:  
  248:                                      LevelId = Ia.Learning.Cl.Models.MoeBook.MoeBookLevelId(xElement.Attribute("id").Value),
  249:                                      GradeId = string.Empty,
  250:                                      PeriodId = string.Empty,
  251:  
  252:                                      ArabicName = xElement.Attribute("arabicName").Value,
  253:                                      Name = xElement.Attribute("name").Value,
  254:                                  }
  255:                     ).ToList<Ia.Learning.Cl.Models.MoeBook>();
  256:                 }
  257:  
  258:                 return levelList;
  259:             }
  260:         }
  261:  
  262:         ////////////////////////////////////////////////////////////////////////////
  263:  
  264:         /// <summary>
  265:         ///
  266:         /// </summary>
  267:         public static List<Ia.Learning.Cl.Models.MoeBook> GradeList
  268:         {
  269:             get
  270:             {
  271:                 if (gradeList == null || gradeList.Count == 0)
  272:                 {
  273:                     gradeList = (from xElement in XDocument.Element("ministry-of-education-books").Descendants("grade")
  274:                                  where xElement.HasElements
  275:                                  select new Ia.Learning.Cl.Models.MoeBook
  276:                                  {
  277:                                      Id = Ia.Learning.Cl.Models.MoeBook.MoeBookGradeId(xElement.Parent.Attribute("id").Value, xElement.Attribute("id").Value),
  278:  
  279:                                      LevelId = Ia.Learning.Cl.Models.MoeBook.MoeBookLevelId(xElement.Parent.Attribute("id").Value),
  280:                                      GradeId = Ia.Learning.Cl.Models.MoeBook.MoeBookGradeId(xElement.Parent.Attribute("id").Value, xElement.Attribute("id").Value),
  281:                                      PeriodId = string.Empty,
  282:  
  283:                                      Name = xElement.Attribute("name").Value,
  284:                                      ArabicName = xElement.Attribute("arabicName").Value,
  285:                                      Url = xElement.Attribute("url").Value,
  286:                                  }
  287:                     ).ToList<Ia.Learning.Cl.Models.MoeBook>();
  288:                 }
  289:  
  290:                 return gradeList;
  291:             }
  292:         }
  293:  
  294:         ////////////////////////////////////////////////////////////////////////////
  295:  
  296:         /// <summary>
  297:         ///
  298:         /// </summary>
  299:         public static List<Ia.Learning.Cl.Models.MoeBook> PeriodList
  300:         {
  301:             get
  302:             {
  303:                 if (periodList == null || periodList.Count == 0)
  304:                 {
  305:                     periodList = (from xElement in XDocument.Element("ministry-of-education-books").Descendants("period")
  306:                                   where xElement.HasElements
  307:                                   select new Ia.Learning.Cl.Models.MoeBook
  308:                                   {
  309:                                       Id = Ia.Learning.Cl.Models.MoeBook.MoeBookPeriodId(xElement.Parent.Parent.Attribute("id").Value, xElement.Parent.Attribute("id").Value, xElement.Attribute("id").Value),
  310:  
  311:                                       LevelId = Ia.Learning.Cl.Models.MoeBook.MoeBookLevelId(xElement.Parent.Parent.Attribute("id").Value),
  312:                                       GradeId = Ia.Learning.Cl.Models.MoeBook.MoeBookGradeId(xElement.Parent.Parent.Attribute("id").Value, xElement.Parent.Attribute("id").Value),
  313:                                       PeriodId = Ia.Learning.Cl.Models.MoeBook.MoeBookPeriodId(xElement.Parent.Parent.Attribute("id").Value, xElement.Parent.Attribute("id").Value, xElement.Attribute("id").Value),
  314:  
  315:                                       //Name = xElement.Attribute("name").Value,
  316:                                       ArabicName = xElement.Attribute("arabicName").Value,
  317:                                       Url = xElement.Attribute("url").Value,
  318:                                   }
  319:                     ).ToList<Ia.Learning.Cl.Models.MoeBook>();
  320:                 }
  321:  
  322:                 return periodList;
  323:             }
  324:         }
  325:  
  326:         ////////////////////////////////////////////////////////////////////////////
  327:  
  328:         /// <summary>
  329:         ///
  330:         /// </summary>
  331:         public static List<Ia.Learning.Cl.Models.MoeBook> CourseList
  332:         {
  333:             get
  334:             {
  335:                 if (courseList == null || courseList.Count == 0)
  336:                 {
  337:                     courseList = (from xElement in XDocument.Element("ministry-of-education-books").Descendants("course")
  338:                                   where !xElement.HasElements
  339:                                   select new Ia.Learning.Cl.Models.MoeBook
  340:                                   {
  341:                                       Id = Ia.Learning.Cl.Models.MoeBook.MoeBookId(xElement.Parent.Parent.Parent.Attribute("id").Value, xElement.Parent.Parent.Attribute("id").Value, xElement.Parent.Attribute("id").Value, xElement.Attribute("id").Value),
  342:  
  343:                                       LevelId = Ia.Learning.Cl.Models.MoeBook.MoeBookLevelId(xElement.Parent.Parent.Parent.Attribute("id").Value),
  344:                                       GradeId = Ia.Learning.Cl.Models.MoeBook.MoeBookGradeId(xElement.Parent.Parent.Parent.Attribute("id").Value, xElement.Parent.Parent.Attribute("id").Value),
  345:                                       PeriodId = Ia.Learning.Cl.Models.MoeBook.MoeBookPeriodId(xElement.Parent.Parent.Parent.Attribute("id").Value, xElement.Parent.Parent.Attribute("id").Value, xElement.Parent.Attribute("id").Value),
  346:  
  347:                                       ArabicName = xElement.Attribute("arabicName").Value,
  348:                                       PdfGoogleDriveFileId = xElement.Attribute("pdfGoogleDriveFileId").Value,
  349:  
  350:                                       PdfDownloadedManuallyDueToSizeIssue = xElement.Attribute("pdfDownloadedManuallyDueToSizeIssue") != null ? xElement.Attribute("pdfDownloadedManuallyDueToSizeIssue").Value : string.Empty,
  351:  
  352:                                       Url = xElement.Attribute("pdfDownloadedManuallyDueToSizeIssue") != null ? xElement.Attribute("pdfDownloadedManuallyDueToSizeIssue").Value : xElement.Attribute("url").Value,
  353:                                   }
  354:                     ).ToList<Ia.Learning.Cl.Models.MoeBook>();
  355:                 }
  356:  
  357:                 return courseList;
  358:             }
  359:         }
  360:  
  361:         ////////////////////////////////////////////////////////////////////////////
  362:  
  363:         /// <summary>
  364:         /// 
  365:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
  366:         /// 
  367:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
  368:         /// 2. Add "using System.Reflection".
  369:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
  370:         /// 
  371:         /// </summary>
  372:         public static XDocument XDocument
  373:         {
  374:             get
  375:             {
  376:                 Assembly assembly;
  377:                 StreamReader streamReader;
  378:  
  379:                 xDocument = null;
  380:                 assembly = Assembly.GetExecutingAssembly();
  381:                 streamReader = new StreamReader(assembly.GetManifestResourceStream("Ia.Learning.Cl.Models.moe-book.xml"));
  382:  
  383:                 try
  384:                 {
  385:                     if (streamReader.Peek() != -1)
  386:                     {
  387:                         xDocument = System.Xml.Linq.XDocument.Load(streamReader);
  388:                     }
  389:                 }
  390:                 catch (Exception)
  391:                 {
  392:                 }
  393:                 finally
  394:                 {
  395:                 }
  396:  
  397:                 return xDocument;
  398:             }
  399:         }
  400:  
  401:         ////////////////////////////////////////////////////////////////////////////
  402:         ////////////////////////////////////////////////////////////////////////////
  403:     }
  404: }