Source

main / Source / Excel / Excel.AddIn / Excel.AddIn / ViewModels / RepositoryViewModel.cs

Full commit
Naethra D ba1cb57 
















































































































































using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Windows.Input;
using DataUp.Excel.BizLogic;
using DataUp.Excel.Common;

namespace DataUp.Excel.Addin
{
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class RepositoryViewModel : ViewModelBase
    {
        private string repositoryName;
        private string userName;
        private string userPassword;

        private ICommand postFileCommand;

        private List<string> repositories;

        #region CustomEvent

        /// <summary>
        /// Capture View window close request
        /// </summary>
        public event EventHandler RequestClose;

        #endregion

        public string RepositoryName
        {
            get
            {
                return this.repositoryName;
            }
            set
            {
                this.repositoryName = value;
                OnNotifyPropertyChanged("RepositoryName");
            }
        }

        public string UserName
        {
            get
            {
                return this.userName;
            }
            set
            {
                this.userName = value;
                OnNotifyPropertyChanged("UserName");
            }
        }

        public string UserPassword
        {
            get
            {
                return this.userPassword;
            }
            set
            {
                this.userPassword = value;
                OnNotifyPropertyChanged("UserPassword");
            }
        }

        public ICommand PostFileCommand
        {
            get
            {
                return postFileCommand;
            }
            set
            {
                if (postFileCommand != value)
                {
                    postFileCommand = value;
                    OnNotifyPropertyChanged("PostFileCommand");
                }
            }
        }

        public List<string> Repositories
        {
            get
            {
                return this.repositories;
            }
            set
            {
                this.repositories = value;
                OnNotifyPropertyChanged("Repositories");
            }
        }

        public RepositoryViewModel()
        {
            InitCommands();
        }

        public void Update(RepositoryModel model)
        {
            if (string.IsNullOrWhiteSpace(model.RepositoryName))
            {
                this.RepositoryName = this.Repositories.FirstOrDefault();
            }
            else
            {
                this.RepositoryName = model.RepositoryName;
            }
            this.UserName = model.UserName;
            this.UserPassword = model.UserPassword;
        }

        /// <summary>
        /// Raise window close event
        /// </summary>
        public void OnRequestClose()
        {
            RequestClose.OnFire(this, EventArgs.Empty);
        }

        private void InitCommands()
        {
            this.PostFileCommand = new DelegateCommand<MetadataListViewModel>(viewModel =>
            {
                Regex reg = new Regex(Common.Constants.HttpAddress);
                if (!string.IsNullOrEmpty(this.UserName)
                       && !string.IsNullOrEmpty(this.RepositoryName))
                {
                    this.OnRequestClose();
                }
                else
                {
                    MessageBox.Show("Please enter all fields => *UserName, *Password, *RepositoryName", "DCXL");
                }
            });
        }
    }
}