Exemple #1
0
        public void Save()
        {
            ValidationErrors.Clear();
            ValidationOnSaving = true;
            OnPropertyChanged(string.Empty);

            if (!HasError)
            {
                Entity.Save();
                DeleteCommand.RaiseCanExecuteChanged();
                OnPropertyChanged("PageTitle");
            }

            OnPropertyChanged(string.Empty);
            ValidationOnSaving = false;
        }
        /// <summary>
        /// Logins this instance.
        /// </summary>
        /// <returns></returns>
        public async Task Login()
        {
            if (ValidationErrors != null)
            {
                ValidationErrors.Clear();
            }

            ValidateModel(_validator, this);

            if (IsModelValid)
            {
                IsLoading = true;

                //string username = "******";
                //string password = "******";

                //bool success = await _auth.Login(username, password, "");
                bool success = await _auth.Login(EmailAddress, Password);

                if (success)
                {
                    ShowViewModel <NavigationViewModel>();
                }
                else
                {
                    Mvx.Resolve <IUserInteraction>().ToastErrorAlert(LanguageResolver.LoginErrorTitle, duration: 3000);
                }

                IsLoading = false;
            }
            else
            {
                string errorMsg = string.Empty;

                if (ValidationErrors != null && ValidationErrors.Count > 0)
                {
                    errorMsg = ValidationErrors.First().ErrorMessage;
                }
                else
                {
                    errorMsg = "An error has occurred.";
                }

                Mvx.Resolve <IUserInteraction>().ToastErrorAlert(errorMsg);
            }
        }
        // Methods
        //
        public bool Validate(PickListModel entity)
        {
            //
            // TODO: put in the BLL class?
            //
            ValidationErrors.Clear();

            /*
             * if (entity.ID <= 0)
             * {
             *  ValidationErrors.Add(new KeyValuePair<string, string>("ID", "ID must be > 0"));
             * }
             * else if (entity.ID > 100)
             * {
             *  ValidationErrors.Add(new KeyValuePair<string, string>("ID", "ID must be less than 100"));
             * }
             */

            return(ValidationErrors.Count == 0);
        }
        public async Task AddCommandHandler()
        {
            ValidationErrors?.Clear();

            ValidateModel(_validator, this);

            if (IsModelValid)
            {
                IsLoading = true;

                bool success = true; //await _dataService.SaveCustomer(_customer);

                if (success)
                {
                    ShowViewModel <ProviderSearchViewModel>();
                }
                else
                {
                    await
                    Mvx.Resolve <IUserInteraction>()
                    .AlertAsync(LanguageResolver.SearchErrorTitle, "No Customers Found");
                }

                IsLoading = false;
            }
            else
            {
                string errorMsg = string.Empty;

                if (ValidationErrors != null && ValidationErrors.Count > 0)
                {
                    errorMsg = ValidationErrors.First().ErrorMessage;
                }
                else
                {
                    errorMsg = "An error has occurred.";
                }

                Mvx.Resolve <IUserInteraction>().ToastErrorAlert(errorMsg);
            }
        }
Exemple #5
0
        /// <summary>
        /// Validate() is used to validate business rules on the business object.
        /// Validates both EF entity validation rules on pending changes as well
        /// as any custom validation rules you implement in the OnValidate() method.
        ///
        /// Do not override this method for custom Validation(). Instead override
        /// OnValidate() or add error entries to the ValidationErrors collection.
        /// <remarks>
        /// If the AutoValidate flag is set to true causes Save()
        /// to automatically call this method. Must be overridden to perform any
        /// validation.
        /// </remarks>
        /// <seealso>Class wwBusiness Class ValidationErrorCollection</seealso>
        /// </summary>
        /// <param name="entity">Optional entity to validate. Defaults to this.Entity</param>
        /// <param name="clearValidationErrors">If true clears all validation errors before processing rules</param>
        /// <returns>True or False.</returns>
        public bool Validate(TEntity entity = null, bool clearValidationErrors = false)
        {
            if (clearValidationErrors)
            {
                ValidationErrors.Clear();
            }

            if (entity == null)
            {
                entity = Entity;
            }

            // No entity - no validation errors
            if (entity == null)
            {
                return(true);
            }

            var validationErrors = Context.GetValidationErrors();

            // First check for model validation errors
            foreach (var entry in validationErrors)
            {
                foreach (var error in entry.ValidationErrors)
                {
                    ValidationErrors.Add(error.ErrorMessage, error.PropertyName);
                }
            }

            // call business object level validation errors
            OnValidate(entity);

            if (ValidationErrors.Count > 0)
            {
                SetError(ValidationErrors.ToString());
                return(false);
            }

            return(true);
        }
Exemple #6
0
        /// <summary>
        /// Searches the command handler.
        /// </summary>
        /// <returns></returns>
        public async Task SearchCommandHandler()
        {
            ValidationErrors?.Clear();

            ValidateModel(_validator, this);

            if (IsModelValid)
            {
                IsLoading = true;

                var applications = await _dataService.FindApplications(SearchText);

                if (applications != null && applications.Count > 0)
                {
                    ShowViewModel <SentListViewModel>(applications);
                }
                else
                {
                    await Mvx.Resolve <IUserInteraction>().AlertAsync(LanguageResolver.SearchErrorTitle, "No Customers Found");
                }

                IsLoading = false;
            }
            else
            {
                string errorMsg = string.Empty;

                if (ValidationErrors != null && ValidationErrors.Count > 0)
                {
                    errorMsg = ValidationErrors.First().ErrorMessage;
                }
                else
                {
                    errorMsg = "An error has occurred.";
                }

                Mvx.Resolve <IUserInteraction>().ToastErrorAlert(errorMsg);
            }
        }
        public bool Validate(User user, bool isNewUser = false)
        {
            ValidationErrors.Clear();

            if (isNewUser)
            {
                if (Context.Users.Any(usr => usr.Username == user.Username))
                {
                    ValidationErrors.Add("Email address is already in use.");
                }
            }

            if (string.IsNullOrEmpty(user.Username))
            {
                ValidationErrors.Add("Email address can't be empty.");
            }

            if (string.IsNullOrEmpty(user.Fullname))
            {
                ValidationErrors.Add("Full name can't be empty.");
            }

            if (string.IsNullOrEmpty(user.Password))
            {
                ValidationErrors.Add("Password can't be empty.");
            }
            else
            {
                // always force password to be updated and hashed even if it was entered as plain text
                user.Password = HashPassword(user.Password, user.Id.ToString());
            }

            if (ValidationErrors.Count > 0)
            {
                ErrorMessage = ValidationErrors.ToString();
                return(false);
            }
            return(true);
        }
        public bool Delete(SqlTransaction trans, SqlConnection conn)
        {
            ValidationErrors.Clear();

            if (IsDeleted)
            {
                return(true);
            }

            DataField idField = IdentityField;

            if (idField == null)
            {
                ValidationErrors.Add("Record does not exist");
                return(false);
            }

            if (conn == null)
            {
                conn = new SqlConnection(SQLDMGlobal.ConnectionString());
            }
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }

            SqlCommand cmd = conn.CreateCommand();

            bool TransactionExists = true;

            if (trans == null)
            {
                TransactionExists = false;
                trans             = conn.BeginTransaction();
            }
            cmd.Transaction = trans;

            try
            {
                foreach (DataRecord r in ChildRecords)
                {
                    if (!r.Delete(trans, conn))
                    {
                        ValidationErrors.AddRange(r.ValidationErrors);
                        throw new DataException("Validation error while saving to " + r.SafeTableName);
                    }
                }

                cmd.CommandText = SQLForDelete(idField);
                cmd.Parameters.Add(idField);
                cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();

                if (!TransactionExists)
                {
                    trans.Commit();
                    conn.Close();
                }

                IsDeleted = true;

                Deleted(this);
            }
            catch (DataException ex)
            {
                if (!TransactionExists)
                {
                    trans.Rollback();
                }

                ValidationErrors.Add(ex.Message);
            }

            return(ValidationErrors.IsValid);
        }
        protected override bool OnValidate(User user)
        {
            bool?isNewUser = IsNewEntity(user);

            if (isNewUser == null)
            {
                isNewUser = true;
            }

            ValidationErrors.Clear();


            if (!IsValidDisplayName(user.UserDisplayName))
            {
                ValidationErrors.Add(
                    "Invalid display name. Name should contain no spaces contain: only alpha numeric characters and dashes and can't start or end with a dash.", "UserDisplayName");
            }

            if (Context.Users.Any(usr => usr.Email == user.Email && usr.Id != user.Id))
            {
                ValidationErrors.Add("Email address is already in use by another user.", "Email");
            }

            if (Context.Users.Any(usr => usr.UserDisplayName == user.UserDisplayName && usr.Id != user.Id))
            {
                ValidationErrors.Add("Display name is already in use by another user.", "UserDisplayName");
            }


            if (string.IsNullOrEmpty(user.Email))
            {
                ValidationErrors.Add("Email address can't be empty.", "Email");
            }

            if (!IsValidEmailAddress(user.Email))
            {
                ValidationErrors.Add("Invalid email format.", "Email");
            }

            if (string.IsNullOrEmpty(user.UserDisplayName))
            {
                ValidationErrors.Add("User display name nan't be empty.", "UserDisplayName");
            }

            if (string.IsNullOrEmpty(user.Password) || user.Password.Length < 5)
            {
                ValidationErrors.Add("Password should be at least 5 characters long.", "Password");
            }
            else
            {
                // always force password to be updated and hashed even if it was entered as plain text
                // this method detects if the password is already encoded
                user.Password = HashPassword(user.Password, user.Id.ToString());
            }

            if (ValidationErrors.Count > 0)
            {
                ErrorMessage = ValidationErrors.ToString();
                return(false);
            }
            return(true);
        }
Exemple #10
0
 protected override void OnStartProcess()
 {
     ProductIds.Clear();
     ValidationErrors.Clear();
 }
Exemple #11
0
 public void ResetValidation()
 {
     Error = false;
     ValidationErrors.Clear();
     StateHasChanged();
 }