Exemplo n.º 1
0
        public ErrorsCollection Validate(UserUserRolePostDTO userUserRolePostDTO, TasksDbContext context)
        {
            ErrorsCollection errorsCollection = new ErrorsCollection {
                Entity = nameof(UserUserRolePostDTO)
            };


            List <string> userRoles = context

                                      .UserRoles
                                      .Select(userRole => userRole.Name)
                                      .ToList();


            if (!userRoles.Contains(userUserRolePostDTO.UserRoleName))
            {
                errorsCollection.ErrorMessages.Add($"The UserRole {userUserRolePostDTO.UserRoleName} does not exist!");
            }

            if (errorsCollection.ErrorMessages.Count > 0)
            {
                return(errorsCollection);
            }
            return(null);
        }
Exemplo n.º 2
0
        public ErrorsCollection Validate(RegisterPostDTO registerPostDTO, TasksDbContext context)
        {
            ErrorsCollection errorsCollection = new ErrorsCollection {
                Entity = nameof(RegisterPostDTO)
            };
            User existing = context.Users.FirstOrDefault(u => u.Username == registerPostDTO.Username);

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