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

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

    1: using Microsoft.AspNetCore.Mvc;
    2: using Microsoft.AspNetCore.Mvc.Rendering;
    3: using System.Diagnostics;
    4: using System.Net;
    5:  
    6: namespace Ia.Islamic.Koran.Belief.Wa.Controllers
    7: {
    8:     ////////////////////////////////////////////////////////////////////////////
    9:  
   10:     /// <summary publish="true">
   11:     ///
   12:     /// </summary>
   13:     /// 
   14:     /// <remarks> 
   15:     /// Copyright © 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   16:     ///
   17:     /// 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
   18:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   19:     ///
   20:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   21:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   22:     /// 
   23:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   24:     /// 
   25:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   26:     /// </remarks> 
   27:     public class ApplicationController : Controller
   28:     {
   29:         ////////////////////////////////////////////////////////////////////////////
   30:  
   31:         /// <summary>
   32:         ///
   33:         /// </summary>
   34:         public IActionResult Index()
   35:         {
   36:             var applicationViewModel = new Ia.Islamic.Koran.Belief.Wa.Models.ApplicationViewModel();
   37:  
   38:             var remoteIpAddress = this.HttpContext.Connection.RemoteIpAddress;
   39:  
   40:             if (Ia.Cl.Models.Default.IsPrivateIp(remoteIpAddress))
   41:             {
   42:                 ChapterAndTopicDataBind(ref applicationViewModel);
   43:  
   44:                 return View(applicationViewModel);
   45:             }
   46:             else return new EmptyResult();
   47:         }
   48:  
   49:         ////////////////////////////////////////////////////////////////////////////
   50:  
   51:         /// <summary>
   52:         ///
   53:         /// </summary>
   54:         public void ChapterAndTopicDataBind(ref Ia.Islamic.Koran.Belief.Wa.Models.ApplicationViewModel applicationViewModel)
   55:         {
   56:             var list = Ia.Islamic.Cl.Model.Data.Default.ChapterListByLanguageSymbol("ar", out _, out _);
   57:             applicationViewModel.ChapterSelectList = new SelectList(list, "Number", "Name");
   58:  
   59:             var hashtable = Ia.Islamic.Cl.Model.Data.Default.TopicHashtable();
   60:             applicationViewModel.TopicSelectList = new SelectList(hashtable, "Key", "Value");
   61:         }
   62:  
   63:         ////////////////////////////////////////////////////////////////////////////
   64:  
   65:         /// <summary>
   66:         ///
   67:         /// </summary>
   68:         public void VerseDataBind(ref Ia.Islamic.Koran.Belief.Wa.Models.ApplicationViewModel applicationViewModel, int chapterNumber)
   69:         {
   70:             applicationViewModel.VerseList = Ia.Islamic.Cl.Model.Data.Default.VerseListByLanguageSymbolAndChapter("ar", chapterNumber, out _, out _);
   71:  
   72:             applicationViewModel.VerseCheckboxViewModelList = new List<Ia.Islamic.Koran.Belief.Wa.Models.VerseCheckboxViewModel>();
   73:  
   74:             foreach (var verse in applicationViewModel.VerseList)
   75:             {
   76:                 var verseCheckboxViewModel = new Ia.Islamic.Koran.Belief.Wa.Models.VerseCheckboxViewModel();
   77:  
   78:                 verseCheckboxViewModel.Id = verse.Id;
   79:                 verseCheckboxViewModel.ChapterNumber = verse.ChapterNumber;
   80:                 verseCheckboxViewModel.VerseNumber = verse.Number;
   81:                 verseCheckboxViewModel.Content = verse.Content;
   82:                 verseCheckboxViewModel.IsChecked = false;
   83:  
   84:                 applicationViewModel.VerseCheckboxViewModelList.Add(verseCheckboxViewModel);
   85:             }
   86:         }
   87:  
   88:         ////////////////////////////////////////////////////////////////////////////
   89:  
   90:         /// <summary>
   91:         ///
   92:         /// </summary>
   93:         public void VerseTopicDataBind(ref Ia.Islamic.Koran.Belief.Wa.Models.ApplicationViewModel applicationViewModel)
   94:         {
   95:             applicationViewModel.VerseTopicList = Ia.Islamic.Cl.Model.Data.VerseTopic.List();
   96:  
   97:             applicationViewModel.VerseTopicCheckboxViewModelList = new List<Ia.Islamic.Koran.Belief.Wa.Models.VerseCheckboxViewModel>();
   98:  
   99:             foreach (var verseTopic in applicationViewModel.VerseTopicList)
  100:             {
  101:                 var verseTopicCheckboxViewModel = new Ia.Islamic.Koran.Belief.Wa.Models.VerseCheckboxViewModel();
  102:  
  103:                 verseTopicCheckboxViewModel.Id = verseTopic.Id;
  104:                 verseTopicCheckboxViewModel.ChapterNumber = verseTopic.ChapterNumber;
  105:                 verseTopicCheckboxViewModel.VerseNumber = verseTopic.VerseNumber;
  106:                 verseTopicCheckboxViewModel.VerseTopicId = verseTopic.TopicId;
  107:                 verseTopicCheckboxViewModel.NumberOfVerses = verseTopic.NumberOfVerses;
  108:                 verseTopicCheckboxViewModel.IsChecked = false;
  109:  
  110:                 applicationViewModel.VerseTopicCheckboxViewModelList.Add(verseTopicCheckboxViewModel);
  111:             }
  112:         }
  113:  
  114:         ////////////////////////////////////////////////////////////////////////////
  115:  
  116:         /// <summary>
  117:         ///
  118:         /// </summary>
  119:         public IActionResult ChapterChanged(Ia.Islamic.Koran.Belief.Wa.Models.ApplicationViewModel applicationViewModel)
  120:         {
  121:             var selectedValue = applicationViewModel.ChapterSelectedValue;
  122:  
  123:             if (int.TryParse(selectedValue, out int chapterNumber))
  124:             {
  125:                 VerseDataBind(ref applicationViewModel, chapterNumber);
  126:  
  127:                 VerseTopicDataBind(ref applicationViewModel);
  128:             }
  129:  
  130:             ChapterAndTopicDataBind(ref applicationViewModel);
  131:  
  132:             return View("Index", applicationViewModel);
  133:         }
  134:  
  135:         ////////////////////////////////////////////////////////////////////////////
  136:  
  137:         /// <summary>
  138:         ///
  139:         /// </summary>
  140:         [HttpPost]
  141:         public IActionResult CreateVerseTopic(Ia.Islamic.Koran.Belief.Wa.Models.ApplicationViewModel applicationViewModel)
  142:         {
  143:             int op, firstVerse, lastVerse, chapter;
  144:             string result, verseId;
  145:             Ia.Islamic.Cl.Model.VerseTopic verseTopic;
  146:  
  147:             var chapterNumber = applicationViewModel.VerseCheckboxViewModelList[0].ChapterNumber;
  148:             var checkboxList = applicationViewModel.VerseCheckboxViewModelList;
  149:  
  150:             var selectedCheckboxList = checkboxList.Where(x => x.IsChecked).ToList();
  151:  
  152:             applicationViewModel.TopicResult = new Ia.Cl.Models.Result();
  153:  
  154:             // below: check if items were selected
  155:             if (selectedCheckboxList.Count > 0)
  156:             {
  157:                 // below: check if the selected items are a sequence
  158:                 firstVerse = selectedCheckboxList[0].VerseNumber;
  159:                 lastVerse = selectedCheckboxList[selectedCheckboxList.Count - 1].VerseNumber;
  160:  
  161:                 if (lastVerse - firstVerse == (selectedCheckboxList.Count - 1))
  162:                 {
  163:                     verseTopic = new Ia.Islamic.Cl.Model.VerseTopic();
  164:  
  165:                     verseId = chapterNumber.ToString().PadLeft(3, '0') + firstVerse.ToString().PadLeft(3, '0');
  166:                     verseTopic.TopicId = int.Parse(applicationViewModel.TopicSelectedValue);
  167:                     verseTopic.NumberOfVerses = selectedCheckboxList.Count;
  168:  
  169:                     verseTopic.VerseNumber = firstVerse;
  170:                     verseTopic.ChapterNumber = chapterNumber;
  171:  
  172:                     verseTopic.Id = verseId + ":" + verseTopic.TopicId + ":" + verseTopic.NumberOfVerses;
  173:  
  174:                     Ia.Islamic.Cl.Model.Data.Default.CreateVerseTopic(verseTopic, verseId, out op, out result);
  175:  
  176:                     applicationViewModel.TopicResult.AddSuccess("تم إضافة تصنيف الاية");
  177:                 }
  178:                 else
  179:                 {
  180:                     applicationViewModel.TopicResult.AddError("lastVerse - firstVerse != (selectedCheckboxList.Count - 1)");
  181:                 }
  182:             }
  183:             else
  184:             {
  185:                 applicationViewModel.TopicResult.AddError("selectedCheckboxList.Count <= 0");
  186:             }
  187:  
  188:             VerseDataBind(ref applicationViewModel, chapterNumber);
  189:  
  190:             VerseTopicDataBind(ref applicationViewModel);
  191:  
  192:             ChapterAndTopicDataBind(ref applicationViewModel);
  193:  
  194:             return View("Index", applicationViewModel);
  195:         }
  196:  
  197:         /*
  198:         ////////////////////////////////////////////////////////////////////////////
  199: 
  200:         /// <summary>
  201:         ///
  202:         /// </summary>
  203:         protected void DeleteVerseTopicButton_Click(object sender, EventArgs e)
  204:         {
  205:             int op;
  206:             string result;
  207:             ArrayList selectedVerseTopicsArrayList;
  208: 
  209:             op = 0;
  210:             result = "";
  211: 
  212:             selectedVerseTopicsArrayList = ReturnSelectedVerseTopics();
  213: 
  214:             // below: check if items were selected
  215:             if (selectedVerseTopicsArrayList.Count > 0)
  216:             {
  217:                 foreach (string verseId in selectedVerseTopicsArrayList)
  218:                 {
  219:                     Ia.Islamic.Cl.Model.Data.VerseTopic.Delete(verseId, out result);
  220:                 }
  221:             }
  222:             else
  223:             {
  224:                 op = -1;
  225:                 result += "Error: You did not select any verse topics. ";
  226:             }
  227: 
  228:             if (op > 0)
  229:             {
  230:                 resultLabel.CssClass = "success";
  231:                 resultLabel.Text = result;
  232:             }
  233:             else if (op == 0)
  234:             {
  235:                 resultLabel.CssClass = "warning";
  236:                 resultLabel.Text = result;
  237:             }
  238:             else
  239:             {
  240:                 resultLabel.CssClass = "error";
  241:                 resultLabel.Text = result;
  242:             }
  243: 
  244:             VerseListRepeater_DataBind();
  245: 
  246:             VerseTopicListRepeater_DataBind();
  247:         }
  248: 
  249: 
  250:         ////////////////////////////////////////////////////////////////////////////
  251: 
  252:         /// <summary>
  253:         ///
  254:         /// </summary>
  255:         private ArrayList ReturnSelectedVerseTopics()
  256:         {
  257:             ArrayList selectedVerseTopicsArrayList;
  258: 
  259:             selectedVerseTopicsArrayList = new ArrayList(10);
  260: 
  261:             foreach (RepeaterItem i in verseTopicListRepeater.Items)
  262:             {
  263:                 // below: retrieve the state of the CheckBox
  264: 
  265:                 CheckBox cb = (CheckBox)i.FindControl("selectVerseTopic");
  266: 
  267:                 if (cb.Checked)
  268:                 {
  269:                     // below: retrieve the value associated with that CheckBox
  270:                     HiddenField hiddenVerseId = (HiddenField)i.FindControl("hiddenVerseTopicId");
  271: 
  272:                     selectedVerseTopicsArrayList.Add(hiddenVerseId.Value);
  273:                 }
  274:             }
  275: 
  276:             return selectedVerseTopicsArrayList;
  277:         }
  278:         */
  279:  
  280:         ////////////////////////////////////////////////////////////////////////////
  281:         ////////////////////////////////////////////////////////////////////////////
  282:  
  283:         /// <summary>
  284:         ///
  285:         /// </summary>
  286:         [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
  287:         public IActionResult Error()
  288:         {
  289:             return View(new Ia.Islamic.Koran.Belief.Wa.Models.ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
  290:         }
  291:  
  292:         ////////////////////////////////////////////////////////////////////////////
  293:         ////////////////////////////////////////////////////////////////////////////
  294:     }
  295:  
  296:     ////////////////////////////////////////////////////////////////////////////
  297:     ////////////////////////////////////////////////////////////////////////////
  298: }