Beispiel #1
0
        private IHttpActionResult ValidateUserData(UserData User, User currentUser = null)
        {
            DataAccessSoapClient ws = new DataAccessSoapClient();

            User[] users = ws.FindUsersByFilter(new UserSearchFilter {
                Email = User.email
            });
            if (!string.IsNullOrEmpty(User.email) && users != null && users.Length > 0 &&
                (currentUser == null || currentUser.Id != users[0].Id))
            {
                return(BadRequest("Another user has already registered the email " + User.email));
            }
            users = ws.FindUsersByFilter(new UserSearchFilter {
                IdDocument = User.document
            });
            if (!string.IsNullOrEmpty(User.document) && users != null && users.Length > 0 &&
                (currentUser == null || currentUser.Id != users[0].Id))
            {
                return(BadRequest("Another user has already registered the document " + User.document));
            }
            users = ws.FindUsersByFilter(new UserSearchFilter {
                Username = User.username
            });
            if (!string.IsNullOrEmpty(User.username) && users != null && users.Length > 0 &&
                (currentUser == null || currentUser.Id != users[0].Id))
            {
                return(BadRequest("Another user has already registered the username " + User.username));
            }
            return(null);
        }
Beispiel #2
0
        // GET: api/Buyers
        public IHttpActionResult Get()
        {
            string            token         = GetAuthToken();
            IHttpActionResult validateToken = ValidateToken(token);

            if (validateToken != null)
            {
                return(validateToken);
            }
            DataAccessSoapClient ws = new DataAccessSoapClient();

            User[] buyers = ws.FindUsersByFilter(new UserSearchFilter {
                Roles = new DataAccessWS.UserRole[] { DataAccessWS.UserRole.BUYER }
            });
            return(Ok(buyers.Select(b => CreateRestUser(b))));
        }