Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Figure 3.4‑13 -  Add to view 

...

In your view model add the following property:

...

Code Block
languagec#
@section scripts
{
  <script>
    'use strict';
    $(document).ready(function () {
      // following section use to highlight border surronding to star container
      $('.star-rating__input').focus(function () {
        $(this).closest('.ratingContainer').addClass('ratingContainerFocus');
      });
      $('.star-rating__input').blur(function () {
        $(this).closest('.ratingContainer').removeClass('ratingContainerFocus');
      });
    });
  </script>
}

1.1.1          Adding Outage the Notices menu

 

Under Views -> MainNavigation, open Index.cshtml.

...

Code Block
languagec#
public ActionResult Index()
{
var vm = new MainNavigationBarViewModel
       {
           HomePageUrl = GetHomePageUrl().ToString(),
           ServicePageUrl = GetServicesPageUrl().ToString(),
           ServiceRequestsPageUrl = GetServiceRequestPageUrl().ToString(),
           NoticesPageUrl = GetNoticesPageUrl().ToString()
       };
 
       return View(vm);
}

Outage Notice View ModelsDisplay notices on service website

Add the two view modelsthe code to retrieve notices of the user.

Code Block
languagec#
public classList<int> OutageNoticeViewModelserviceIds {=  List<int> serviceIds =     public string Header { get; set; }
        public string Text { get; set; }
 public IEnumerable<string> AffectedServices { get; set; }
}
 
public class OutageNoticesViewModel
{
        public List<OutageNoticeViewModel> OutageNotices { get; set; }
        public ServiceMenuBarViewModel ServiceTitleBar { get; set; }
}

Create a new view.

Code Block
languagehtml
@model Models.OutageNoticesViewModel
 
@section ServiceTitleBar
{
    @Html.Partial("_ServiceTitleBar", Model.ServiceTitleBar)
}
 
<div class="container">
    <div class="row">
        <h2>@Html.Raw(Resource.UpcomingOutages)</h2>
        <p>@Html.Raw(Resource.TechnicalSupport)</p>
 
        <hr style="border: #AF3C43 1px solid;" />
 
        @if (Model.OutageNotices.Any())
        {
            <p>@Html.Raw(Resource.PlannedOutages)</p>
 
            foreach (var m in Model.OutageNotices)
            {
                <section class="alert alert-warning">
                    <div>
                        <h3>@Html.Raw(m.Header)</h3>
                        <p>@Html.Raw(m.Body)</p>
 
                        <h4>@Resource.AffectedServices</h4>
                        <ul>
                            @foreach (var service in m.AffectedServices)
                            {
                                <li>@service</li>
                            }
                        </ul>
                    </div>
                </section>
            }
 
        }
        else
        {
            <p>@Html.Raw(Resource.NoOutages)</p>
        }
    </div>
</div>

 OutageNoticeController

 Create a new controller called OutageNoticeController.

Add the following code.

Code Block
languagec#
[UrlRouteController(Name = "OutageNoticeControllerRoute")]
    public class OutageNoticeController : PortalBaseController
    {
        private readonly IOutageNoticeManager _outageNoticeManager;
        private readonly IServiceCatalog _serviceCatalog;
 
        // GET: Notices
        public OutageNoticeController(IUserManager userManager, ILogger<OutageNoticeController> logger, ICache cache, IServiceSettingManager serviceSettingManager, IOutageNoticeManager outageNoticeManager, IServiceCatalog serviceCatalog) : base(userManager, logger, cache, serviceSettingManager)
        {
            _outageNoticeManager = outageNoticeManager;
            _serviceCatalog = serviceCatalog;
        }
 
        [UrlRouteEng(Path = "Notices")]
        [UrlRouteFra(Path = "Avis")]
        public async Task<ActionResult> Index()
        {
            var userOutageNotices = await _outageNoticeManager.GetByUserId(CurrentUser.Id);
            var services = await _serviceCatalog.GetAll();
            var outageNotices = userOutageNotices.Select(outageNotice =>
                new
                {
                    ServiceNames = services.Where(serviceInfo => outageNotice.Services.Any(serviceId => serviceId == serviceInfo.Id)),
                    Header = Utility.IsEnglish() ? outageNotice.EnglishHeaderText : outageNotice.FrenchHeaderText,
                    Body = Utility.IsEnglish() ? outageNotice.EnglishBodyText : outageNotice.FrenchBodyText
                })
                .Select(service => new OutageNoticeViewModel
                {
                    Body = service.Body,
                    Header = service.Header,
                    AffectedServices = service.ServiceNames.Select(serviceInfo => Utility.IsEnglish() ? serviceInfo.FriendlyNameEn : serviceInfo.FriendlyNameFr)
                });
 
            var viewModel = new OutageNoticesViewModel
            {
                ServiceTitleBar = CreateServiceTitleButtons(Resources.Resource.Notices, "bell"),
                OutageNotices = outageNotices
            };
 
            return View(viewModel);
        }
    } new List<int>{ <user's service id>, 6 }; //6: MyTC Account
//Get notices of the services
 var userNotices = await _noticeManager.GetByServiceId(serviceIds);
 

Modify the view to load the notices
Example:

...

1.1.1          Application user properties

...

All files are scanned for viruses using the OSWAT MetaDefender version 45.1.2. For more information see this document.

...