Ejemplo n.º 1
0
        public ErrorsCollection Validate(RegisterPostModel registerPostModel, ExpensesDbContext context)
        {
            ErrorsCollection errorsCollection = new ErrorsCollection {
                Entity = nameof(RegisterPostModel)
            };
            User existing = context.Users.FirstOrDefault(u => u.Username == registerPostModel.Username);

            if (existing != null)
            {
                errorsCollection.ErrorMessages.Add($"The username {registerPostModel.Username} is already taken!");
            }
            if (registerPostModel.Password.Length < 6)
            {
                errorsCollection.ErrorMessages.Add("Thee password cannot be shorter than 6 characters!");
            }
            int numberOfDigits = 0;

            foreach (char c in registerPostModel.Password)
            {
                if (c >= '0' && c <= '9')
                {
                    numberOfDigits++;
                }
            }
            //if(numberOfDigits < 2)
            //{
            //    errorsCollection.ErrorMessages.Add("Thee password must contain at least two digits!");
            //}
            //if(errorsCollection.ErrorMessages.Count > 0)
            //{
            //    return errorsCollection;
            //}
            return(null);
        }
Ejemplo n.º 2
0
        public ErrorsCollection Validate(UserUserRolePostModel userUserRolePostModel, ExpensesDbContext context)
        {
            ErrorsCollection errorsCollection = new ErrorsCollection { Entity = nameof(UserUserRolePostModel) };

            List<string> userRoles = context
                .UserRoles
                .Select(userRole => userRole.Name)
                .ToList();

            if (!userRoles.Contains(userUserRolePostModel.UserRoleName))
            {
                errorsCollection.ErrorMessages.Add($"The UserRole {userUserRolePostModel.UserRoleName} does not exist!");
            }
            if (errorsCollection.ErrorMessages.Count > 0)
            {
                return errorsCollection;
            }
            return null;
        }
Ejemplo n.º 3
0
        public ErrorsCollection Validate(UserPostModel userPostModel, ExpensesDbContext context)
        {
            ErrorsCollection errorsCollection = new ErrorsCollection {
                Entity = nameof(UserPostModel)
            };
            User existing = context.Users.FirstOrDefault(u => u.Username == userPostModel.UserName);

            if (existing != null)
            {
                errorsCollection.ErrorMessages.Add($"The username {userPostModel.UserName} is already taken !");
            }
            if (userPostModel.Password.Length < 7)
            {
                errorsCollection.ErrorMessages.Add("The password cannot be shorter than 7 characters !");
            }
            if (errorsCollection.ErrorMessages.Count > 0)
            {
                return(errorsCollection);
            }
            return(null);
        }