Ejemplo n.º 1
0
        public IRepositoryAsync <TEntity> GetRepositoryAsync <TEntity>() where TEntity : class
        {
            if (_repositoriesAsync == null)
            {
                _repositoriesAsync = new Dictionary <Type, object>();
            }
            var type = typeof(TEntity);

            if (!_repositoriesAsync.ContainsKey(type))
            {
                switch (type.ToString())
                {
                case "Project.Entity.Account":
                    _repositoriesAsync[type] = new AccountRepositoryAsync(Context);
                    break;

                case "Project.Entity.User":
                    _repositoriesAsync[type] = new UserRepositoryAsync(Context);
                    break;

                case "Project.Entity.Role":
                    _repositoriesAsync[type] = new RoleRepositoryAsync(Context);
                    break;
                }
            }
            return((IRepositoryAsync <TEntity>)_repositoriesAsync[type]);
        }
        private async void ExecuteLoginCommand()
        {
            User user = await UserRepositoryAsync.GetAsync(_email, _password);

            if (user == null)
            {
                _isValidLogin = false;
                OnPropertyChanged(nameof(IsValidLogin));
                return;
                //invalid credentials make error message visible
            }

            //Login user
            UserSessionManager.LoginUser(user, _navigationService);
        }
Ejemplo n.º 3
0
        private async void ExecuteRegisterUserCommand()
        {
            //Register a new user (buyer or seller) in the database
            var user = new User
            {
                Name        = Name,
                Email       = Email,
                Password    = Password,
                DateCreated = DateTime.Now,
                UserTypeId  = _isSeller ? (int)UserTypeEnum.Seller : (int)UserTypeEnum.Buyer
            };

            int saved = await UserRepositoryAsync.SaveAsync(user);

            if (saved <= 0)
            {
                return;             //TODO: Show error message
            }
            User dbUser = await UserRepositoryAsync.GetAsync(user.Email, user.Password);

            //Login user
            UserSessionManager.LoginUser(dbUser, _navigationService);
        }