Exemple #1
0
        public async Task <List <ValidationResult> > ValidateNewUser(User user, string confirmPassword)
        {
            if (user.password.Equals(confirmPassword))
            {
                ValidationContext ctx = new ValidationContext(user);
                var results           = new List <ValidationResult>();
                if (!Validator.TryValidateObject(user, ctx, results, true))
                {
                    return(results);
                }
                else
                {
                    IDataBase context = new SQLiteDB();
                    bool      result  = await context.AddUser(user);

                    if (result)
                    {
                        return(new List <ValidationResult>());
                    }
                    else
                    {
                        return(new List <ValidationResult> {
                            new ValidationResult("Email or Login is already in use", new List <string> {
                                "login"
                            })
                        });
                    }
                }
            }
            else
            {
                return(new List <ValidationResult> {
                    new ValidationResult("Passwords mismatch", new List <string> {
                        "confirmPassword"
                    })
                });
            }
        }