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

using AdventureWorks.Client.Objects;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Specialized;
using System.Threading;
using System.Threading.Tasks;
using Xomega.Framework;
using Xomega.Framework.Views;

namespace AdventureWorks.Client.ViewModels
{
    public partial class SalesOrderListViewModel : SearchViewModel
    {
        public SalesOrderList ListObj => List as SalesOrderList;
        public SalesOrderCriteria CritObj => List.CriteriaObject as SalesOrderCriteria;

        public SalesOrderListViewModel(IServiceProvider sp) : base(sp)
        {
        }

        public override void Initialize()
        {
            base.Initialize();
            List = ServiceProvider.GetService<SalesOrderList>();
            List.CriteriaObject = ServiceProvider.GetService<SalesOrderCriteria>();
        }

        #region Link LinkDetails

        public virtual NameValueCollection LinkDetails_Params(DataRow row)
        {
            NameValueCollection query = new NameValueCollection()
            {
                { "SalesOrderId", ListObj.SalesOrderIdProperty.GetStringValue(ValueFormat.EditString, row) },
                { ViewParams.Mode.Param, ViewParams.Mode.Inline },
                { ViewParams.QuerySource, "LinkDetails" },
            };
            return query;
        }

        public virtual void LinkDetails_Command(IView tgtView, IView curView, DataRow row)
        {
            NameValueCollection query = LinkDetails_Params(row);
            ViewModel tgtModel = ServiceProvider.GetService<SalesOrderViewModel>();
            NavigateTo(tgtModel, tgtView, query, this, curView);
        }

        public virtual async Task LinkDetails_CommandAsync(IAsyncView tgtView, IAsyncView curView, DataRow row, CancellationToken token = default)
        {
            NameValueCollection query = LinkDetails_Params(row);
            ViewModel tgtModel = ServiceProvider.GetService<SalesOrderViewModel>();
            await NavigateToAsync(tgtModel, tgtView, query, this, curView, token);
        }

        public virtual bool LinkDetails_Enabled(DataRow row)
        {
            return true;
        }
        #endregion

        #region Link LinkNew

        public virtual NameValueCollection LinkNew_Params()
        {
            NameValueCollection query = new NameValueCollection()
            {
                { ViewParams.Action.Param, ViewParams.Action.Create },
                { ViewParams.Mode.Param, ViewParams.Mode.Inline },
                { ViewParams.QuerySource, "LinkNew" },
            };
            return query;
        }

        public virtual void LinkNew_Command(IView tgtView, IView curView)
        {
            NameValueCollection query = LinkNew_Params();
            ViewModel tgtModel = ServiceProvider.GetService<SalesOrderViewModel>();
            NavigateTo(tgtModel, tgtView, query, this, curView);
        }

        public virtual async Task LinkNew_CommandAsync(IAsyncView tgtView, IAsyncView curView, CancellationToken token = default)
        {
            NameValueCollection query = LinkNew_Params();
            ViewModel tgtModel = ServiceProvider.GetService<SalesOrderViewModel>();
            await NavigateToAsync(tgtModel, tgtView, query, this, curView, token);
        }

        public virtual bool LinkNew_Enabled()
        {
            return true;
        }
        #endregion
    }
}