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

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

    1: using Microsoft.AspNetCore.Authorization;
    2: using Microsoft.AspNetCore.Identity;
    3: using Microsoft.AspNetCore.Mvc;
    4: using System.Diagnostics;
    5: using System.Net;
    6:  
    7: namespace Ia.Ftn.Wa.Controllers
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     ///
   13:     /// </summary>
   14:     /// 
   15:     /// <remarks> 
   16:     /// Copyright � 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   17:     ///
   18:     /// 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
   19:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   20:     ///
   21:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   22:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   23:     /// 
   24:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   25:     /// 
   26:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   27:     /// </remarks> 
   28:     [Authorize]
   29:     public class ApplicationController : Controller
   30:     {
   31:         private readonly UserManager<Ia.Ftn.Cl.Models.StaffIdentityUser> userManager;
   32:         private readonly RoleManager<IdentityRole> roleManager;
   33:  
   34:         private static Ia.Ftn.Wa.Models.Application.IdentityViewModel currentIdentityViewModel = new Ia.Ftn.Wa.Models.Application.IdentityViewModel();
   35:  
   36:         /////////////////////////////////////////////////////////////////////////////////
   37:  
   38:         /// <summary>
   39:         ///
   40:         /// </summary>
   41:         public ApplicationController(UserManager<Ia.Ftn.Cl.Models.StaffIdentityUser> _userManager, RoleManager<IdentityRole> _roleManager)
   42:         {
   43:             userManager = _userManager;
   44:             roleManager = _roleManager;
   45:         }
   46:  
   47:         /////////////////////////////////////////////////////////////////////////////////
   48:  
   49:         /// <summary>
   50:         ///
   51:         /// </summary>
   52:         [HttpGet]
   53:         public IActionResult Index()
   54:         {
   55:             return View();
   56:         }
   57:  
   58:         /////////////////////////////////////////////////////////////////////////////////
   59:  
   60:         /// <summary>
   61:         ///
   62:         /// </summary>
   63:         [HttpGet]
   64:         public IActionResult Configuration()
   65:         {
   66:             var applicationViewModel = new Ia.Ftn.Wa.Models.Application.ApplicationViewModel();
   67:  
   68:             Ia.Ftn.Wa.Models.Application.Index.Configuration(roleManager, ref applicationViewModel);
   69:  
   70:             return View(applicationViewModel);
   71:         }
   72:  
   73:         /////////////////////////////////////////////////////////////////////////////////
   74:         /////////////////////////////////////////////////////////////////////////////////
   75:  
   76:         /// <summary>
   77:         ///
   78:         /// </summary>
   79:         [HttpGet]
   80:         public IActionResult Setting()
   81:         {
   82:             var applicationViewModel = new Ia.Ftn.Wa.Models.Application.ApplicationViewModel();
   83:  
   84:             Ia.Ftn.Wa.Models.Application.Index.SettingViewModel(userManager, ref applicationViewModel);
   85:  
   86:             return View(applicationViewModel);
   87:         }
   88:  
   89:         /////////////////////////////////////////////////////////////////////////////////
   90:  
   91:         /// <summary>
   92:         ///
   93:         /// </summary>
   94:         [HttpPost]
   95:         public IActionResult Setting(Ia.Ftn.Wa.Models.Application.ApplicationViewModel applicationViewModel, string commandName)
   96:         {
   97:             Ia.Ftn.Wa.Models.Application.Index.SettingPost(userManager, roleManager, ref applicationViewModel, commandName);
   98:  
   99:             Ia.Ftn.Wa.Models.Application.Index.SettingViewModel(userManager, ref applicationViewModel);
  100:  
  101:             return View(applicationViewModel);
  102:         }
  103:  
  104:         /////////////////////////////////////////////////////////////////////////////////
  105:  
  106:         /// <summary>
  107:         ///
  108:         /// </summary>
  109:         [HttpGet]
  110:         public IActionResult Contact()
  111:         {
  112:             return View();
  113:         }
  114:  
  115:         /////////////////////////////////////////////////////////////////////////////////
  116:         /////////////////////////////////////////////////////////////////////////////////
  117:  
  118:         /// <summary>
  119:         ///
  120:         /// </summary>
  121:         [HttpGet]
  122:         public IActionResult Mail()
  123:         {
  124:             var applicationViewModel = new Ia.Ftn.Wa.Models.Application.ApplicationViewModel();
  125:  
  126:             Ia.Ftn.Wa.Models.Application.Index.SettingViewModel(userManager, ref applicationViewModel);
  127:  
  128:             return View(applicationViewModel);
  129:         }
  130:  
  131:         /////////////////////////////////////////////////////////////////////////////////
  132:  
  133:         /// <summary>
  134:         ///
  135:         /// </summary>
  136:         [HttpPost]
  137:         public IActionResult Mail(Ia.Ftn.Wa.Models.Application.ApplicationViewModel applicationViewModel)
  138:         {
  139:             Ia.Ftn.Wa.Models.Application.Index.MailPost(userManager, roleManager, ref applicationViewModel, applicationViewModel.MailSelectedValue);
  140:  
  141:             Ia.Ftn.Wa.Models.Application.Index.SettingViewModel(userManager, ref applicationViewModel);
  142:  
  143:             return View(applicationViewModel);
  144:         }
  145:  
  146:         /////////////////////////////////////////////////////////////////////////////////
  147:         /////////////////////////////////////////////////////////////////////////////////
  148:  
  149:         /// <summary>
  150:         ///
  151:         /// </summary>
  152:         [HttpGet]
  153:         public IActionResult Telegram()
  154:         {
  155:             return View();
  156:         }
  157:  
  158:         /////////////////////////////////////////////////////////////////////////////////
  159:         /////////////////////////////////////////////////////////////////////////////////
  160:  
  161:         /*
  162: 
  163:         /////////////////////////////////////////////////////////////////////////////////
  164: 
  165:         /// <summary>
  166:         ///
  167:         /// </summary>
  168:         [HttpPost]
  169:         [ValidateAntiForgeryToken]
  170:         [Route("application/register")]
  171:         public async Task<IActionResult> Register(Ia.Ftn.Wa.Models.AccountViewModels.RegisterViewModel model, string returnUrl = null)
  172:         {
  173:             ViewData["ReturnUrl"] = returnUrl;
  174:             if (ModelState.IsValid)
  175:             {
  176:                 var user = new Ia.Ftn.Cl.Models.StaffIdentityUser { UserName = model.Email, Email = model.Email };
  177:                 var result = await userManager.CreateAsync(user, model.Password);
  178:                 if (result.Succeeded)
  179:                 {
  180:                     // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
  181:                     // Send an email with this link
  182:                     //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
  183:                     //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
  184:                     //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
  185:                     //    "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
  186:                     await signInManager.SignInAsync(user, isPersistent: false);
  187:                     _logger.LogInformation(3, "User created a new account with password.");
  188:                     return RedirectToLocal(returnUrl);
  189:                 }
  190:                 AddErrors(result);
  191:             }
  192: 
  193:             // If we got this far, something failed, redisplay form
  194:             return View(model);
  195:         }
  196:         */
  197:  
  198:         /////////////////////////////////////////////////////////////////////////////////
  199:         /////////////////////////////////////////////////////////////////////////////////
  200:  
  201:         /// <summary>
  202:         ///
  203:         /// </summary>
  204:         [HttpGet]
  205:         [Route("application/register")]
  206:         public IActionResult Register()
  207:         {
  208:             var identityViewModel = new Ia.Ftn.Wa.Models.Application.IdentityViewModel();
  209:  
  210:             identityViewModel.CurrentStaffIdentityUser = userManager.GetUserAsync(this.User).Result;
  211:  
  212:             Ia.Ftn.Wa.Models.Application.Index2.RegisterViewModel(ref currentIdentityViewModel, ref identityViewModel);
  213:  
  214:             return View("Register", identityViewModel);
  215:         }
  216:  
  217:         /////////////////////////////////////////////////////////////////////////////////
  218:  
  219:         /// <summary>
  220:         ///
  221:         /// </summary>
  222:         [HttpPost]
  223:         [Route("application/register")]
  224:         public IActionResult Register(Ia.Ftn.Wa.Models.Application.IdentityViewModel identityViewModel, string commandName)
  225:         {
  226:             identityViewModel.CurrentStaffIdentityUser = userManager.GetUserAsync(this.User).Result;
  227:  
  228:             if (commandName == "insert")
  229:             {
  230:                 Ia.Ftn.Wa.Models.Application.Index2.CreateUser(userManager, roleManager, ref identityViewModel);
  231:             }
  232:             else if (commandName == "delete")
  233:             {
  234:                 var userName = WebUtility.HtmlDecode(identityViewModel.UserSelectedValue);
  235:  
  236:                 Ia.Ftn.Wa.Models.Application.Index2.DeleteUser(userManager, ref identityViewModel, userName);
  237:             }
  238:             else
  239:             {
  240:             }
  241:  
  242:             Ia.Ftn.Wa.Models.Application.Index2.RegisterViewModel(ref currentIdentityViewModel, ref identityViewModel);
  243:  
  244:             return View("Register", identityViewModel);
  245:         }
  246:  
  247:         /////////////////////////////////////////////////////////////////////////////////
  248:         /////////////////////////////////////////////////////////////////////////////////
  249:  
  250:         /// <summary>
  251:         ///
  252:         /// </summary>
  253:         [HttpGet]
  254:         [Route("application/role")]
  255:         public IActionResult Role()
  256:         {
  257:             var identityViewModel = new Ia.Ftn.Wa.Models.Application.IdentityViewModel();
  258:  
  259:             Ia.Ftn.Wa.Models.Application.Index2.RoleViewModel(roleManager, ref identityViewModel);
  260:  
  261:             return View(identityViewModel);
  262:         }
  263:  
  264:         /////////////////////////////////////////////////////////////////////////////////
  265:  
  266:         /// <summary>
  267:         ///
  268:         /// </summary>
  269:         [HttpPost]
  270:         [Route("application/role")]
  271:         public IActionResult ManageRole(Ia.Ftn.Wa.Models.Application.IdentityViewModel identityViewModel, string commandName)
  272:         {
  273:             string roleName;
  274:  
  275:             if (commandName == "createRole")
  276:             {
  277:                 roleName = WebUtility.HtmlDecode(identityViewModel.CreateRoleNameText);
  278:  
  279:                 Ia.Ftn.Wa.Models.Application.Index2.CreateRole(roleManager, ref identityViewModel, roleName);
  280:             }
  281:             else if (commandName == "deleteRole")
  282:             {
  283:                 roleName = WebUtility.HtmlDecode(identityViewModel.RoleSelectedValue);
  284:  
  285:                 Ia.Ftn.Wa.Models.Application.Index2.DeleteRole(roleManager, ref identityViewModel, roleName);
  286:             }
  287:             else
  288:             {
  289:             }
  290:  
  291:             Ia.Ftn.Wa.Models.Application.Index2.RoleViewModel(roleManager, ref identityViewModel);
  292:  
  293:             return View("Role", identityViewModel);
  294:         }
  295:  
  296:         /////////////////////////////////////////////////////////////////////////////////
  297:         /////////////////////////////////////////////////////////////////////////////////
  298:  
  299:         /// <summary>
  300:         ///
  301:         /// </summary>
  302:         [HttpGet]
  303:         [Route("application/user")]
  304:         public new IActionResult User_()
  305:         {
  306:             var identityViewModel = new Ia.Ftn.Wa.Models.Application.IdentityViewModel();
  307:  
  308:             identityViewModel.CurrentStaffIdentityUser = userManager.GetUserAsync(this.User).Result;
  309:             identityViewModel.UserManager = userManager;
  310:             identityViewModel.RoleManager = roleManager;
  311:  
  312:             Ia.Ftn.Wa.Models.Application.Index2.RegisterViewModel(ref currentIdentityViewModel, ref identityViewModel);
  313:  
  314:             return View("User", identityViewModel);
  315:         }
  316:  
  317:         /////////////////////////////////////////////////////////////////////////////////
  318:  
  319:         /// <summary>
  320:         ///
  321:         /// </summary>
  322:         [HttpPost]
  323:         [Route("application/user")]
  324:         public IActionResult User_(Ia.Ftn.Wa.Models.Application.IdentityViewModel identityViewModel, string commandName, string userId)
  325:         {
  326:             identityViewModel.CurrentStaffIdentityUser = userManager.GetUserAsync(this.User).Result;
  327:             identityViewModel.UserManager = userManager;
  328:             identityViewModel.RoleManager = roleManager;
  329:  
  330:             Ia.Ftn.Wa.Models.Application.Index2.IdentityPost(ref identityViewModel, commandName, userId);
  331:  
  332:             Ia.Ftn.Wa.Models.Application.Index2.RegisterViewModel(ref currentIdentityViewModel, ref identityViewModel);
  333:  
  334:             return View("User", identityViewModel);
  335:         }
  336:  
  337:         /////////////////////////////////////////////////////////////////////////////////
  338:         /////////////////////////////////////////////////////////////////////////////////
  339:  
  340:         /// <summary>
  341:         ///
  342:         /// </summary>
  343:         [HttpGet]
  344:         [Route("application/user-role")]
  345:         public new IActionResult UserRole()
  346:         {
  347:             var identityViewModel = new Ia.Ftn.Wa.Models.Application.IdentityViewModel();
  348:  
  349:             identityViewModel.CurrentStaffIdentityUser = userManager.GetUserAsync(this.User).Result;
  350:  
  351:             Ia.Ftn.Wa.Models.Application.Index2.UserRoleViewModel(userManager, roleManager, ref currentIdentityViewModel, ref identityViewModel);
  352:  
  353:             return View("UserRole", identityViewModel);
  354:         }
  355:  
  356:         /////////////////////////////////////////////////////////////////////////////////
  357:  
  358:         /// <summary>
  359:         ///
  360:         /// </summary>
  361:         [HttpPost]
  362:         [Route("application/user-role")]
  363:         public IActionResult UserRole(Ia.Ftn.Wa.Models.Application.IdentityViewModel identityViewModel, string commandName)
  364:         {
  365:             identityViewModel.CurrentStaffIdentityUser = userManager.GetUserAsync(this.User).Result;
  366:  
  367:             if (commandName == "addUserToRole")
  368:             {
  369:                 Ia.Ftn.Wa.Models.Application.Index2.AddUserToRole(userManager, roleManager, ref identityViewModel);
  370:             }
  371:             else if (commandName == "deleteUserFromRole")
  372:             {
  373:                 var userName = WebUtility.HtmlDecode(identityViewModel.UserSelectedValue);
  374:  
  375:                 Ia.Ftn.Wa.Models.Application.Index2.DeleteUserFromRole(userManager, roleManager, ref identityViewModel);
  376:             }
  377:             else
  378:             {
  379:             }
  380:  
  381:             Ia.Ftn.Wa.Models.Application.Index2.UserRoleViewModel(userManager, roleManager, ref currentIdentityViewModel, ref identityViewModel);
  382:  
  383:             return View("UserRole", identityViewModel);
  384:         }
  385:  
  386:         /////////////////////////////////////////////////////////////////////////////////
  387:  
  388:         /// <summary>
  389:         ///
  390:         /// </summary>
  391:         [HttpGet]
  392:         [Route("/application/user-guide")]
  393:         public IActionResult UserGuide()
  394:         {
  395:             return View();
  396:         }
  397:  
  398:         /////////////////////////////////////////////////////////////////////////////////
  399:  
  400:         /// <summary>
  401:         ///
  402:         /// </summary>
  403:         [HttpGet]
  404:         [Route("/application/maintenance-guide")]
  405:         public IActionResult MaintenanceGuide()
  406:         {
  407:             return View();
  408:         }
  409:  
  410:         /////////////////////////////////////////////////////////////////////////////////
  411:  
  412:         /// <summary>
  413:         ///
  414:         /// </summary>
  415:         [HttpGet]
  416:         public IActionResult Glossary()
  417:         {
  418:             return View();
  419:         }
  420:  
  421:         /////////////////////////////////////////////////////////////////////////////////
  422:  
  423:         /// <summary>
  424:         ///
  425:         /// </summary>
  426:         [HttpGet]
  427:         public IActionResult Api()
  428:         {
  429:             return View();
  430:         }
  431:  
  432:         /////////////////////////////////////////////////////////////////////////////////
  433:         /////////////////////////////////////////////////////////////////////////////////
  434:  
  435:         /// <summary>
  436:         ///
  437:         /// </summary>
  438:         [HttpGet]
  439:         public IActionResult Credential()
  440:         {
  441:             var parameterViewModel = new Ia.Ftn.Wa.Models.ParameterViewModel();
  442:  
  443:             ApiKeyList(ref parameterViewModel);
  444:  
  445:             return View("Credential", parameterViewModel);
  446:         }
  447:  
  448:         /////////////////////////////////////////////////////////////////////////////////
  449:  
  450:         /// <summary>
  451:         ///
  452:         /// </summary>
  453:         [HttpPost]
  454:         public IActionResult Credential(Ia.Ftn.Wa.Models.ParameterViewModel parameterViewModel)
  455:         {
  456:             parameterViewModel.String1 = Ia.Cl.Models.Cryptography.ApiKey.Generate();
  457:  
  458:             ApiKeyList(ref parameterViewModel);
  459:  
  460:             return View("Credential", parameterViewModel);
  461:         }
  462:  
  463:         ////////////////////////////////////////////////////////////////////////////
  464:  
  465:         /// <summary>
  466:         ///
  467:         /// </summary>
  468:         private void ApiKeyList(ref Ia.Ftn.Wa.Models.ParameterViewModel parameterViewModel)
  469:         {
  470:             var list = Ia.Ftn.Cl.Models.Business.Application.Default.ApiKeyList;
  471:  
  472:             var s = string.Empty;
  473:  
  474:             s += "Name&nbsp;|&nbsp;" + "Created&nbsp;|&nbsp;" + "Key<br/>\r\n";
  475:  
  476:             foreach (var l in list)
  477:             {
  478:                 s += l.Name + "&nbsp;|&nbsp;" + l.Created + "&nbsp;|&nbsp;" + l.Key + "<br/>\r\n";
  479:             }
  480:  
  481:             parameterViewModel.String2 = s;
  482:         }
  483:  
  484:         /////////////////////////////////////////////////////////////////////////////////
  485:         /////////////////////////////////////////////////////////////////////////////////
  486:  
  487:         /// <summary>
  488:         ///
  489:         /// </summary>
  490:         [HttpGet]
  491:         public IActionResult Ont()
  492:         {
  493:             var applicationViewModel = new Ia.Ftn.Wa.Models.Application.ApplicationViewModel();
  494:  
  495:             applicationViewModel.NokiaEquipmentTypeList = Ia.Ftn.Cl.Models.Business.Nokia.Ont.EquipmentTypeList.ToList();
  496:  
  497:             applicationViewModel.HuaweiEquipmentTypeList = Ia.Ftn.Cl.Models.Business.Huawei.Ont.EquipmentTypeList.ToList();
  498:  
  499:             return View("Ont", applicationViewModel);
  500:         }
  501:  
  502:         /////////////////////////////////////////////////////////////////////////////////
  503:         /////////////////////////////////////////////////////////////////////////////////
  504:  
  505:         /// <summary>
  506:         ///
  507:         /// </summary>
  508:         [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
  509:         public IActionResult Error()
  510:         {
  511:             return View(new Ia.Ftn.Wa.Models.ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
  512:         }
  513:  
  514:         /////////////////////////////////////////////////////////////////////////////////
  515:         /////////////////////////////////////////////////////////////////////////////////
  516:     }
  517:  
  518:     /////////////////////////////////////////////////////////////////////////////////
  519:     /////////////////////////////////////////////////////////////////////////////////
  520: }