Esempio n. 1
0
        private void LoginCommandAction()
        {
            if (string.IsNullOrEmpty(this.UserName) || string.IsNullOrEmpty(this.Password))
            {
                this.ErrorMessageVisibility = true;
            }
            else
            {
                SubscribeIsBusyAction(callback =>
                {
                    _clientModel.AuthenticateUser(this.UserName, this.Password, result =>
                    {
                        if (result == null)
                        {
                            this.ErrorMessageVisibility = true;
                        }
                        else
                        {
                            _globals.ConnectedUser = result;
                            this.LoginUserName     = _globals.ConnectedUser.FullName;

                            _systemModel.ListUserOptions(_globals.ConnectedUser, resultUserOptions =>
                            {
                                _globals.UserOptions = resultUserOptions;
                                // load the companies
                                _clientModel.ListUserCompanies(_globals.ConnectedUser, resultUserCompanies =>
                                {
                                    _globals.UserCompanies = resultUserCompanies;
                                    this.ActiveCompany     = _globals.CompanySelected = (from x in _globals.UserCompanies
                                                                                         where x.CompanyId == int.Parse(_globals.GetUserOption("DefaultCompanyId").OptionValue)
                                                                                         select x).FirstOrDefault();

                                    if (_globals.CompanySelected == null)
                                    {
                                        // TODO : do something here. This error should never happen
                                        throw new Exception("The company selected does not exist in the database, please contact the system administrator.");
                                    }
                                    else
                                    {
                                        _systemModel.ListCompanyOptions(_globals.CompanySelected, resultCompanyOptions =>
                                        {
                                            _globals.CompanyOptions = resultCompanyOptions;

                                            this.ErrorMessageVisibility   = false;
                                            this.LoginBoxVisibility       = false;
                                            this.UserDetailsBoxVisibility = true;

                                            // Get the Menu For the Company
                                            _systemModel.ListCompanyMenu(_globals.CompanySelected, resultMenu =>
                                            {
                                                this.CustomMenu     = resultMenu;
                                                this.MenuVisibility = true;
                                                callback();
                                            });
                                        });
                                    }
                                });
                            });
                        }
                    });
                });
            }
        }