//---------------------------------------------------------------------------------------------
// This file was AUTO-GENERATED by "ASP.NET Views" Xomega.Net generator.
//
// Manual CHANGES to this file WILL BE LOST when the code is regenerated.
//---------------------------------------------------------------------------------------------

using AdventureWorks.Client.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xomega.Framework;
using Xomega.Framework.Web;

namespace AdventureWorks.Client.Web
{
    public partial class SalesOrderListView : WebSearchView
    {
        protected SalesOrderListViewModel VM => Model as SalesOrderListViewModel;

        public SalesOrderListView()
        {
            Model = ServiceProvider.GetService<SalesOrderListViewModel>();
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Split();
            SubscribeToChildEvents(uclSalesOrderView);
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (VM == null) return;
            Page.RegisterAsyncTask(new PageAsyncTask(async () =>
            {
                LinkNew.Enabled = VM.LinkNew_Enabled();
                await Task.CompletedTask;
            }));
        }

        protected virtual void LinkDetails_Click(object sender, CommandEventArgs e)
        {
            if (VM == null) return;
            int index = int.Parse(e.CommandArgument.ToString());
            DataRow row = VM.ListObj.GetData()[index];
            Page.RegisterAsyncTask(new PageAsyncTask(async () =>
                await VM.LinkDetails_CommandAsync(uclSalesOrderView, null, row)));
        }

        protected virtual void LinkNew_Click(object sender, CommandEventArgs e)
        {
            if (VM == null) return;
            Page.RegisterAsyncTask(new PageAsyncTask(async () =>
                await VM.LinkNew_CommandAsync(uclSalesOrderView, null)));
        }

        public virtual void PermaLink_Click(object sender, EventArgs e)
        {
            if (VM?.List?.CriteriaObject == null) return;
            Response.Redirect(WebUtil.AddQueryString(Request.RawUrl, VM.List.CriteriaObject.ToNameValueCollection()));
        }
    }
}