<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Client/ClientMaster.master" CodeBehind="Dashboard.aspx.vb" Inherits="Web.Dashboard1" %>
<%@ MasterType VirtualPath="ClientMaster.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="phContent" runat="server">

    <div class="container">

        <asp:SqlDataSource ID="sqlMessages" runat="server"
            SelectCommand="
                SELECT msg.startTime, msg.[type], msg.[message], cust.[name],
                    CASE msg.type WHEN 'error' THEN 'danger' WHEN 'notification' THEN 'info' WHEN 'warning' THEN 'warning' ELSE '' END bgcolor
                FROM web_ClientMessages msg LEFT JOIN ServiceContract sc ON sc.id=msg.contractId LEFT JOIN Customer cust ON cust.id=sc.CustomerID
                WHERE isActive = 1 AND startTime < GETDATE() AND endTime > GETDATE()
                AND (ISNULL(contractId,0)=0 OR contractId IN (SELECT contractId FROM web_ClientContractsMap WHERE clientId=@clientId))
                ORDER BY startTime DESC">
            <SelectParameters>
                <asp:Parameter Name="clientId" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:Repeater ID="rptMessages" runat="server" DataSourceID="sqlMessages">
            <ItemTemplate>
                <div class="card mb-3">
                    <div class="card-header bg-<%# Eval("bgcolor") %>">
                        <%# Eval("name") %>
                        <small class="float-right"><%# CDate(Eval("startTime")).ToString("M/d/yyyy") %></small>
                    </div>
                    <div class="card-body">
                        <p><%# Eval("message") %></p>
                    </div>
                </div>
            </ItemTemplate>
        </asp:Repeater>

        <p><asp:Literal ID="litMessage" runat="server" /></p>

    </div>

</asp:Content>
