using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xrm;
using Microsoft.Xrm.Client;

namespace ToolsCRM.user_sites
{


    public partial class License : System.Web.UI.Page
    {


        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = Session["user"].ToString();

            var xrm = new XrmServiceContext("Xrm");

            var userLicenses =
                from userLicence in xrm.SystemUserSet
                select new
                {
                    Uzytkownik = userLicence.FullName,
                    Adres = userLicence.Address1_City,
                    Domena = userLicence.DomainName,
                    Email = userLicence.InternalEMailAddress
                };


            GridView1.DataSource = userLicenses;
            GridView1.DataBind();
        }

        public void CountLicense()
        {
            var xrm = new XrmServiceContext("Xrm");

            var userLicences =
               (from userLicence in xrm.SystemUserSet
                select userLicence).ToList();

            int count = userLicences.Count();
            Response.Write(count);

        }
        /*
        public void ShowTime() 
        {
            Response.Write(DateTime.Today.ToShortDateString());
        }
        */
        protected void Wyloguj_Click(object sender, EventArgs e)
        {
            Session["admin"] = null;
            Session["user"] = null;
            Response.Redirect("../Index.aspx");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("../user.aspx");
        }
    }
}